From 02efbd31a8d6f027798b97687fb9b5e2e88a8d4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Fri, 8 Jun 2012 19:10:19 +0200
Subject: [PATCH] Convert files to Unix EOL

---
 doc/userguide/models/fs2000ns_steadystate.m   |  104 +-
 doc/userguide/models/fsdat.m                  |  418 ++--
 matlab/discretionary_policy_1.m               |  314 +--
 matlab/discretionary_policy_engine.m          |  598 ++---
 matlab/ident_bruteforce.m                     |  202 +-
 mex/sources/estimation/tests/DsgeLikelihood.m |  690 +++---
 .../rawdata_euromodel_1.m                     | 1934 ++++++++---------
 .../logposterior_dll_test/sweuromodel_dll.mod |  368 ++--
 .../estimation/tests/rawdata_euromodel_1.m    | 1934 ++++++++---------
 .../estimation/tests/sweuromodel_dll.mod      |  364 ++--
 .../k_order_perturbation/tests/fs2000k.mod    |  238 +-
 tests/AIM/data_ca1.m                          |  200 +-
 tests/AIM/fs2000_b1L1L_AIM_steadystate.m      |  128 +-
 tests/AIM/fs2000_b1L1L_steadystate.m          |  128 +-
 tests/AIM/fsdat.m                             |  418 ++--
 .../example1_varexo_det_bytecode.mod          |  116 +-
 .../dsgevar_forward_calibrated_lambda.mod     |  158 +-
 .../dsgevar_forward_estimated_lambda.mod      |  160 +-
 tests/dsge-var/simul_hybrid.mod               |  100 +-
 tests/ep/linear.mod                           |   88 +-
 tests/fs2000/fs2000a_steadystate.m            |  118 +-
 .../fs2000a_steadystate.m                     |  118 +-
 tests/kalman_filter_smoother/testsmoother.m   |  112 +-
 tests/ls2003/data_ca1.m                       |  200 +-
 tests/measurement_errors/data_ca1.m           |  200 +-
 .../ftd_2s_caseall_upperchol3v.m              |  456 ++--
 .../ftd_2s_caseall_upperchol4v.m              |  662 +++---
 .../ftd_2s_caseall_upperchol6v.m              |  910 ++++----
 .../ftd_2s_caseall_upperchol7v.m              | 1050 ++++-----
 .../ms-sbvar/archive-files/ftd_RSvensson_4v.m |  376 ++--
 tests/ms-sbvar/archive-files/ftd_cholesky.m   |  502 ++---
 tests/ms-sbvar/archive-files/ftd_non_rec_5v.m |  384 ++--
 tests/ms-sbvar/archive-files/ftd_simszha5v.m  |  380 ++--
 .../ms-sbvar/archive-files/ftd_upperchol3v.m  |  340 +--
 .../ms-sbvar/archive-files/ftd_upperchol4v.m  |  356 +--
 .../ms-sbvar/archive-files/ftd_upperchol5v.m  |  374 ++--
 .../ms-sbvar/archive-files/ftd_upperchol6v.m  |  388 ++--
 .../ms-sbvar/archive-files/ftd_upperchol7v.m  |  408 ++--
 tests/optimal_policy/nk_ramsey.mod            |  180 +-
 .../optimal_policy/nk_ramsey_expectation.mod  |  192 +-
 .../nk_ramsey_expectation_a.mod               |  208 +-
 tests/pi2004/idata.m                          |    8 +-
 tests/practicing/datasaver.m                  |  116 +-
 tests/recursive/data_ca1.m                    |  200 +-
 tests/steady_state/multi_leads.mod            |   54 +-
 tests/steady_state/walsh1_initval.mod         |  136 +-
 tests/steady_state/walsh1_old_ss.mod          |  102 +-
 tests/steady_state/walsh1_ssm.mod             |  144 +-
 tests/steady_state/walsh1_ssm_block.mod       |  144 +-
 tests/test.m                                  |    6 +-
 50 files changed, 8742 insertions(+), 8742 deletions(-)

diff --git a/doc/userguide/models/fs2000ns_steadystate.m b/doc/userguide/models/fs2000ns_steadystate.m
index e55b408730..3720ec68e6 100644
--- a/doc/userguide/models/fs2000ns_steadystate.m
+++ b/doc/userguide/models/fs2000ns_steadystate.m
@@ -1,53 +1,53 @@
-% computes the steady state of fs2000 analyticaly
-% largely inspired by the program of F. Schorfheide
-function [ys,check] = fs2000ns_steadystate(ys,exe)
-  global M_
-  
-  alp = M_.params(1); 
-  bet = M_.params(2); 
-  gam = M_.params(3); 
-  mst = M_.params(4); 
-  rho = M_.params(5); 
-  psi = M_.params(6); 
-  del = M_.params(7); 
-
-  check = 0;
-  
-  dA = exp(gam);
-  gst = 1/dA;
-  m = mst;
-  
-  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
-  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
-  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
-  n  = xist/(nust+xist);
-  P  = xist + nust;
-  k  = khst*n;
-  l  = psi*mst*n/( (1-psi)*(1-n) );
-  c  = mst/P;
-  d  = l - mst + 1;
-  y  = k^alp*n^(1-alp)*gst^alp;
-  R  = mst/bet;
-  W  = l/n;
-  ist  = y-c;
-  q  = 1 - d;
-  e = 1;
-  
-  P_obs = 1;
-  Y_obs = 1;
-  
-  ys =[
-m     
-P     
-c     
-e     
-W     
-R     
-k     
-d     
-n     
-l     
-Y_obs 
-P_obs 
-y     
+% computes the steady state of fs2000 analyticaly
+% largely inspired by the program of F. Schorfheide
+function [ys,check] = fs2000ns_steadystate(ys,exe)
+  global M_
+  
+  alp = M_.params(1); 
+  bet = M_.params(2); 
+  gam = M_.params(3); 
+  mst = M_.params(4); 
+  rho = M_.params(5); 
+  psi = M_.params(6); 
+  del = M_.params(7); 
+
+  check = 0;
+  
+  dA = exp(gam);
+  gst = 1/dA;
+  m = mst;
+  
+  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
+  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
+  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
+  n  = xist/(nust+xist);
+  P  = xist + nust;
+  k  = khst*n;
+  l  = psi*mst*n/( (1-psi)*(1-n) );
+  c  = mst/P;
+  d  = l - mst + 1;
+  y  = k^alp*n^(1-alp)*gst^alp;
+  R  = mst/bet;
+  W  = l/n;
+  ist  = y-c;
+  q  = 1 - d;
+  e = 1;
+  
+  P_obs = 1;
+  Y_obs = 1;
+  
+  ys =[
+m     
+P     
+c     
+e     
+W     
+R     
+k     
+d     
+n     
+l     
+Y_obs 
+P_obs 
+y     
 dA          ];
\ No newline at end of file
diff --git a/doc/userguide/models/fsdat.m b/doc/userguide/models/fsdat.m
index 5a0e3658d4..aba209b908 100644
--- a/doc/userguide/models/fsdat.m
+++ b/doc/userguide/models/fsdat.m
@@ -1,210 +1,210 @@
-data_q = [
-18.02 1474.5 150.2
-17.94 1538.2 150.9
-18.01 1584.5 151.4
-18.42 1644.1 152
-18.73 1678.6 152.7
-19.46 1693.1 153.3
-19.55 1724   153.9
-19.56 1758.2 154.7
-19.79 1760.6 155.4
-19.77 1779.2 156
-19.82 1778.8 156.6
-20.03 1790.9 157.3
-20.12 1846   158
-20.1  1882.6 158.6
-20.14 1897.3 159.2
-20.22 1887.4 160
-20.27 1858.2 160.7
-20.34 1849.9 161.4
-20.39 1848.5 162
-20.42 1868.9 162.8
-20.47 1905.6 163.6
-20.56 1959.6 164.3
-20.62 1994.4 164.9
-20.78 2020.1 165.7
-21    2030.5 166.5
-21.2  2023.6 167.2
-21.33 2037.7 167.9
-21.62 2033.4 168.7
-21.71 2066.2 169.5
-22.01 2077.5 170.2
-22.15 2071.9 170.9
-22.27 2094   171.7
-22.29 2070.8 172.5
-22.56 2012.6 173.1
-22.64 2024.7 173.8
-22.77 2072.3 174.5
-22.88 2120.6 175.3
-22.92 2165   176.045
-22.91 2223.3  176.727
-22.94 2221.4  177.481
-23.03 2230.95 178.268
-23.13 2279.22 179.694
-23.22 2265.48 180.335
-23.32 2268.29 181.094
-23.4  2238.57 181.915
-23.45 2251.68 182.634
-23.51 2292.02 183.337
-23.56 2332.61 184.103
-23.63 2381.01 184.894
-23.75 2422.59 185.553
-23.81 2448.01 186.203
-23.87 2471.86 186.926
-23.94 2476.67 187.68
-24    2508.7  188.299
-24.07 2538.05 188.906
-24.12 2586.26 189.631
-24.29 2604.62 190.362
-24.35 2666.69 190.954
-24.41 2697.54 191.56
-24.52 2729.63 192.256
-24.64 2739.75 192.938
-24.77 2808.88 193.467
-24.88 2846.34 193.994
-25.01 2898.79 194.647
-25.17 2970.48 195.279
-25.32 3042.35 195.763
-25.53 3055.53 196.277
-25.79 3076.51 196.877
-26.02 3102.36 197.481
-26.14 3127.15 197.967
-26.31 3129.53 198.455
-26.6  3154.19 199.012
-26.9  3177.98 199.572
-27.21 3236.18 199.995
-27.49 3292.07 200.452
-27.75 3316.11 200.997
-28.12 3331.22 201.538
-28.39 3381.86 201.955
-28.73 3390.23 202.419
-29.14 3409.65 202.986
-29.51 3392.6  203.584
-29.94 3386.49 204.086
-30.36 3391.61 204.721
-30.61 3422.95 205.419
-31.02 3389.36 206.13
-31.5  3481.4  206.763
-31.93 3500.95 207.362
-32.27 3523.8  208
-32.54 3533.79 208.642
-33.02 3604.73 209.142
-33.2  3687.9  209.637
-33.49 3726.18 210.181
-33.95 3790.44 210.737
-34.36 3892.22 211.192
-34.94 3919.01 211.663
-35.61 3907.08 212.191
-36.29 3947.11 212.708
-37.01 3908.15 213.144
-37.79 3922.57 213.602
-38.96 3879.98 214.147
-40.13 3854.13 214.7
-41.05 3800.93 215.135
-41.66 3835.21 215.652
-42.41 3907.02 216.289
-43.19 3952.48 216.848
-43.69 4044.59 217.314
-44.15 4072.19 217.776
-44.77 4088.49 218.338
-45.57 4126.39 218.917
-46.32 4176.28 219.427
-47.07 4260.08 219.956
-47.66 4329.46 220.573
-48.63 4328.33 221.201
-49.42 4345.51 221.719
-50.41 4510.73 222.281
-51.27 4552.14 222.933
-52.35 4603.65 223.583
-53.51 4605.65 224.152
-54.65 4615.64 224.737
-55.82 4644.93 225.418
-56.92 4656.23 226.117
-58.18 4678.96 226.754
-59.55 4566.62 227.389
-61.01 4562.25 228.07
-62.59 4651.86 228.689
-64.15 4739.16 229.155
-65.37 4696.82 229.674
-66.65 4753.02 230.301
-67.87 4693.76 230.903
-68.86 4615.89 231.395
-69.72 4634.88 231.906
-70.66 4612.08 232.498
-71.44 4618.26 233.074
-72.08 4662.97 233.546
-72.83 4763.57 234.028
-73.48 4849    234.603
-74.19 4939.23 235.153
-75.02 5053.56 235.605
-75.58 5132.87 236.082
-76.25 5170.34 236.657
-76.81 5203.68 237.232
-77.63 5257.26 237.673
-78.25 5283.73 238.176
-78.76 5359.6  238.789
-79.45 5393.57 239.387
-79.81 5460.83 239.861
-80.22 5466.95 240.368
-80.84 5496.29 240.962
-81.45 5526.77 241.539
-82.09 5561.8  242.009
-82.68 5618    242.52
-83.33 5667.39 243.12
-84.09 5750.57 243.721
-84.67 5785.29 244.208
-85.56 5844.05 244.716
-86.66 5878.7  245.354
-87.44 5952.83 245.966
-88.45 6010.96 246.46
-89.39 6055.61 247.017
-90.13 6087.96 247.698
-90.88 6093.51 248.374
-92    6152.59 248.928
-93.18 6171.57 249.564
-94.14 6142.1  250.299
-95.11 6078.96 251.031
-96.27 6047.49 251.65
-97    6074.66 252.295
-97.7  6090.14 253.033
-98.31 6105.25 253.743
-99.13 6175.69 254.338
-99.79 6214.22 255.032
-100.17 6260.74 255.815
-100.88 6327.12 256.543
-101.84 6327.93 257.151
-102.35 6359.9  257.785
-102.83 6393.5  258.516
-103.51 6476.86 259.191
-104.13 6524.5  259.738
-104.71 6600.31 260.351
-105.39 6629.47 261.04
-106.09 6688.61 261.692
-106.75 6717.46 262.236
-107.24 6724.2  262.847
-107.75 6779.53 263.527
-108.29 6825.8  264.169
-108.91 6882    264.681
-109.24 6983.91 265.258
-109.74 7020    265.887
-110.23 7093.12 266.491
-111    7166.68 266.987
-111.43 7236.5  267.545
-111.76 7311.24 268.171
-112.08 7364.63 268.815
-];
-%GDPD  GDPQ   GPOP
-
-series = zeros(193,2);
-series(:,2) = data_q(:,1);
-series(:,1) = 1000*data_q(:,2)./data_q(:,3);
-
-Y_obs = series(:,1);
-P_obs = series(:,2);
-
-series = series(2:193,:)./series(1:192,:);
-
-gy_obs = series(:,1);
-gp_obs = series(:,2);
-
+data_q = [
+18.02 1474.5 150.2
+17.94 1538.2 150.9
+18.01 1584.5 151.4
+18.42 1644.1 152
+18.73 1678.6 152.7
+19.46 1693.1 153.3
+19.55 1724   153.9
+19.56 1758.2 154.7
+19.79 1760.6 155.4
+19.77 1779.2 156
+19.82 1778.8 156.6
+20.03 1790.9 157.3
+20.12 1846   158
+20.1  1882.6 158.6
+20.14 1897.3 159.2
+20.22 1887.4 160
+20.27 1858.2 160.7
+20.34 1849.9 161.4
+20.39 1848.5 162
+20.42 1868.9 162.8
+20.47 1905.6 163.6
+20.56 1959.6 164.3
+20.62 1994.4 164.9
+20.78 2020.1 165.7
+21    2030.5 166.5
+21.2  2023.6 167.2
+21.33 2037.7 167.9
+21.62 2033.4 168.7
+21.71 2066.2 169.5
+22.01 2077.5 170.2
+22.15 2071.9 170.9
+22.27 2094   171.7
+22.29 2070.8 172.5
+22.56 2012.6 173.1
+22.64 2024.7 173.8
+22.77 2072.3 174.5
+22.88 2120.6 175.3
+22.92 2165   176.045
+22.91 2223.3  176.727
+22.94 2221.4  177.481
+23.03 2230.95 178.268
+23.13 2279.22 179.694
+23.22 2265.48 180.335
+23.32 2268.29 181.094
+23.4  2238.57 181.915
+23.45 2251.68 182.634
+23.51 2292.02 183.337
+23.56 2332.61 184.103
+23.63 2381.01 184.894
+23.75 2422.59 185.553
+23.81 2448.01 186.203
+23.87 2471.86 186.926
+23.94 2476.67 187.68
+24    2508.7  188.299
+24.07 2538.05 188.906
+24.12 2586.26 189.631
+24.29 2604.62 190.362
+24.35 2666.69 190.954
+24.41 2697.54 191.56
+24.52 2729.63 192.256
+24.64 2739.75 192.938
+24.77 2808.88 193.467
+24.88 2846.34 193.994
+25.01 2898.79 194.647
+25.17 2970.48 195.279
+25.32 3042.35 195.763
+25.53 3055.53 196.277
+25.79 3076.51 196.877
+26.02 3102.36 197.481
+26.14 3127.15 197.967
+26.31 3129.53 198.455
+26.6  3154.19 199.012
+26.9  3177.98 199.572
+27.21 3236.18 199.995
+27.49 3292.07 200.452
+27.75 3316.11 200.997
+28.12 3331.22 201.538
+28.39 3381.86 201.955
+28.73 3390.23 202.419
+29.14 3409.65 202.986
+29.51 3392.6  203.584
+29.94 3386.49 204.086
+30.36 3391.61 204.721
+30.61 3422.95 205.419
+31.02 3389.36 206.13
+31.5  3481.4  206.763
+31.93 3500.95 207.362
+32.27 3523.8  208
+32.54 3533.79 208.642
+33.02 3604.73 209.142
+33.2  3687.9  209.637
+33.49 3726.18 210.181
+33.95 3790.44 210.737
+34.36 3892.22 211.192
+34.94 3919.01 211.663
+35.61 3907.08 212.191
+36.29 3947.11 212.708
+37.01 3908.15 213.144
+37.79 3922.57 213.602
+38.96 3879.98 214.147
+40.13 3854.13 214.7
+41.05 3800.93 215.135
+41.66 3835.21 215.652
+42.41 3907.02 216.289
+43.19 3952.48 216.848
+43.69 4044.59 217.314
+44.15 4072.19 217.776
+44.77 4088.49 218.338
+45.57 4126.39 218.917
+46.32 4176.28 219.427
+47.07 4260.08 219.956
+47.66 4329.46 220.573
+48.63 4328.33 221.201
+49.42 4345.51 221.719
+50.41 4510.73 222.281
+51.27 4552.14 222.933
+52.35 4603.65 223.583
+53.51 4605.65 224.152
+54.65 4615.64 224.737
+55.82 4644.93 225.418
+56.92 4656.23 226.117
+58.18 4678.96 226.754
+59.55 4566.62 227.389
+61.01 4562.25 228.07
+62.59 4651.86 228.689
+64.15 4739.16 229.155
+65.37 4696.82 229.674
+66.65 4753.02 230.301
+67.87 4693.76 230.903
+68.86 4615.89 231.395
+69.72 4634.88 231.906
+70.66 4612.08 232.498
+71.44 4618.26 233.074
+72.08 4662.97 233.546
+72.83 4763.57 234.028
+73.48 4849    234.603
+74.19 4939.23 235.153
+75.02 5053.56 235.605
+75.58 5132.87 236.082
+76.25 5170.34 236.657
+76.81 5203.68 237.232
+77.63 5257.26 237.673
+78.25 5283.73 238.176
+78.76 5359.6  238.789
+79.45 5393.57 239.387
+79.81 5460.83 239.861
+80.22 5466.95 240.368
+80.84 5496.29 240.962
+81.45 5526.77 241.539
+82.09 5561.8  242.009
+82.68 5618    242.52
+83.33 5667.39 243.12
+84.09 5750.57 243.721
+84.67 5785.29 244.208
+85.56 5844.05 244.716
+86.66 5878.7  245.354
+87.44 5952.83 245.966
+88.45 6010.96 246.46
+89.39 6055.61 247.017
+90.13 6087.96 247.698
+90.88 6093.51 248.374
+92    6152.59 248.928
+93.18 6171.57 249.564
+94.14 6142.1  250.299
+95.11 6078.96 251.031
+96.27 6047.49 251.65
+97    6074.66 252.295
+97.7  6090.14 253.033
+98.31 6105.25 253.743
+99.13 6175.69 254.338
+99.79 6214.22 255.032
+100.17 6260.74 255.815
+100.88 6327.12 256.543
+101.84 6327.93 257.151
+102.35 6359.9  257.785
+102.83 6393.5  258.516
+103.51 6476.86 259.191
+104.13 6524.5  259.738
+104.71 6600.31 260.351
+105.39 6629.47 261.04
+106.09 6688.61 261.692
+106.75 6717.46 262.236
+107.24 6724.2  262.847
+107.75 6779.53 263.527
+108.29 6825.8  264.169
+108.91 6882    264.681
+109.24 6983.91 265.258
+109.74 7020    265.887
+110.23 7093.12 266.491
+111    7166.68 266.987
+111.43 7236.5  267.545
+111.76 7311.24 268.171
+112.08 7364.63 268.815
+];
+%GDPD  GDPQ   GPOP
+
+series = zeros(193,2);
+series(:,2) = data_q(:,1);
+series(:,1) = 1000*data_q(:,2)./data_q(:,3);
+
+Y_obs = series(:,1);
+P_obs = series(:,2);
+
+series = series(2:193,:)./series(1:192,:);
+
+gy_obs = series(:,1);
+gp_obs = series(:,2);
+
 ti = [1950:0.25:1997.75];
\ No newline at end of file
diff --git a/matlab/discretionary_policy_1.m b/matlab/discretionary_policy_1.m
index 2541df0a78..9deb655ff7 100644
--- a/matlab/discretionary_policy_1.m
+++ b/matlab/discretionary_policy_1.m
@@ -1,157 +1,157 @@
-function [dr,ys,info]=discretionary_policy_1(oo_,Instruments)
-
-% Copyright (C) 2007-2012 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/>.
-
-global M_ options_
-persistent Hold
-
-options_ = set_default_option(options_,'qz_criterium',1.000001);
-options_ = set_default_option(options_,'solve_maxit',3000);
-
-% safeguard against issues like running ramsey policy first and then running discretion
-if isfield(M_,'orig_model')
-    orig_model = M_.orig_model;
-    M_.endo_nbr = orig_model.endo_nbr;
-    M_.endo_names = orig_model.endo_names;
-    M_.lead_lag_incidence = orig_model.lead_lag_incidence;
-    M_.maximum_lead = orig_model.maximum_lead;
-    M_.maximum_endo_lead = orig_model.maximum_endo_lead;
-    M_.maximum_lag = orig_model.maximum_lag;
-    M_.maximum_endo_lag = orig_model.maximum_endo_lag;
-else
-	M_.orig_model = M_;
-end
-
-beta = get_optimal_policy_discount_factor(M_.params,M_.param_names);
-
-exo_nbr = M_.exo_nbr;
-if isfield(M_,'orig_model')
-    orig_model = M_.orig_model;
-    endo_nbr = orig_model.endo_nbr;
-    endo_names = orig_model.endo_names;
-    lead_lag_incidence = orig_model.lead_lag_incidence;
-    MaxLead = orig_model.maximum_lead;
-    MaxLag = orig_model.maximum_lag;
-else
-	endo_names = M_.endo_names;
-	endo_nbr = M_.endo_nbr;
-	MaxLag=M_.maximum_lag;
-	MaxLead=M_.maximum_lead;
-    lead_lag_incidence = M_.lead_lag_incidence;
-end
-
-[U,Uy,W] = feval([M_.fname,'_objective_static'],zeros(endo_nbr,1),[], M_.params);
-if any(any(Uy~=0))
-    error(['discretionary_policy: the objective function must have zero ' ...
-           'first order derivatives'])
-end
-
-W=reshape(W,endo_nbr,endo_nbr);
-
-klen = MaxLag + MaxLead + 1;
-iyv=lead_lag_incidence';
-% Find the jacobian
-z = repmat(zeros(endo_nbr,1),1,klen);
-z = z(nonzeros(iyv)) ;
-it_ = MaxLag + 1 ;
-
-if exo_nbr == 0
-    oo_.exo_steady_state = [] ;
-end
-[junk,jacobia_] = feval([M_.fname '_dynamic'],z, [oo_.exo_simul ...
-                    oo_.exo_det_simul], M_.params, zeros(endo_nbr,1), it_);
-if any(junk~=0)
-    error(['discretionary_policy: the model must be written in deviation ' ...
-           'form and not have constant terms'])
-end
-
-eq_nbr= size(jacobia_,1);
-instr_nbr=endo_nbr-eq_nbr;
-
-instr_id=nan(instr_nbr,1);
-for j=1:instr_nbr
-	vj=deblank(Instruments(j,:));
-	vj_id=strmatch(vj,endo_names,'exact');
-	if ~isempty(vj_id)
-		instr_id(j)=vj_id;
-	else
-		error([mfilename,':: instrument ',vj,' not found'])
-	end
-end
-
-Indices={'lag','0','lead'};
-iter=1;
-for j=1:numel(Indices)
-    eval(['A',Indices{j},'=zeros(eq_nbr,endo_nbr);'])
-	if strcmp(Indices{j},'0')||(strcmp(Indices{j},'lag') && MaxLag)||(strcmp(Indices{j},'lead') && MaxLead)
-	    [junk,row,col]=find(lead_lag_incidence(iter,:));
-	    eval(['A',Indices{j},'(:,row)=jacobia_(:,col);'])
-		iter=iter+1;
-	end
-end
-B=jacobia_(:,nnz(iyv)+1:end);
-
-%%% MAIN ENGINE %%%
-qz_criterium = options_.qz_criterium;
-solve_maxit = options_.solve_maxit;
-discretion_tol = options_.discretionary_tol;
-
-if ~isempty(Hold)
-	[H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium,Hold);
-else
-	[H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium);
-end
-
-if info
-    dr=[];
-    return
-else
-	Hold=H;
-	% Hold=[]; use this line if persistent command is not used.
-end
-% update the following elements
-
-LLI=lead_lag_incidence;
-LLI(MaxLag,:)=any(H);
-
-LLI=LLI';
-tmp=find(LLI);
-LLI(tmp)=1:numel(tmp);
-
-M_.lead_lag_incidence = LLI';
-
-% set the state
-dr=oo_.dr;
-dr.ys =zeros(endo_nbr,1);
-dr=set_state_space(dr,M_);
-order_var=dr.order_var;
-
-T=H(order_var,order_var);
-dr.ghu=G(order_var,:);
-Selection=any(T);
-dr.ghx=T(:,Selection);
-
-ys=NondistortionarySteadyState(M_);
-dr.ys=ys; % <--- dr.ys =zeros(NewEndo_nbr,1);
-
-function ys=NondistortionarySteadyState(M_)
-if exist([M_.fname,'_steadystate.m'],'file')
-	eval(['ys=',M_.fname,'_steadystate.m;'])
-else
-	ys=zeros(M_.endo_nbr,1);
-end
+function [dr,ys,info]=discretionary_policy_1(oo_,Instruments)
+
+% Copyright (C) 2007-2012 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/>.
+
+global M_ options_
+persistent Hold
+
+options_ = set_default_option(options_,'qz_criterium',1.000001);
+options_ = set_default_option(options_,'solve_maxit',3000);
+
+% safeguard against issues like running ramsey policy first and then running discretion
+if isfield(M_,'orig_model')
+    orig_model = M_.orig_model;
+    M_.endo_nbr = orig_model.endo_nbr;
+    M_.endo_names = orig_model.endo_names;
+    M_.lead_lag_incidence = orig_model.lead_lag_incidence;
+    M_.maximum_lead = orig_model.maximum_lead;
+    M_.maximum_endo_lead = orig_model.maximum_endo_lead;
+    M_.maximum_lag = orig_model.maximum_lag;
+    M_.maximum_endo_lag = orig_model.maximum_endo_lag;
+else
+	M_.orig_model = M_;
+end
+
+beta = get_optimal_policy_discount_factor(M_.params,M_.param_names);
+
+exo_nbr = M_.exo_nbr;
+if isfield(M_,'orig_model')
+    orig_model = M_.orig_model;
+    endo_nbr = orig_model.endo_nbr;
+    endo_names = orig_model.endo_names;
+    lead_lag_incidence = orig_model.lead_lag_incidence;
+    MaxLead = orig_model.maximum_lead;
+    MaxLag = orig_model.maximum_lag;
+else
+	endo_names = M_.endo_names;
+	endo_nbr = M_.endo_nbr;
+	MaxLag=M_.maximum_lag;
+	MaxLead=M_.maximum_lead;
+    lead_lag_incidence = M_.lead_lag_incidence;
+end
+
+[U,Uy,W] = feval([M_.fname,'_objective_static'],zeros(endo_nbr,1),[], M_.params);
+if any(any(Uy~=0))
+    error(['discretionary_policy: the objective function must have zero ' ...
+           'first order derivatives'])
+end
+
+W=reshape(W,endo_nbr,endo_nbr);
+
+klen = MaxLag + MaxLead + 1;
+iyv=lead_lag_incidence';
+% Find the jacobian
+z = repmat(zeros(endo_nbr,1),1,klen);
+z = z(nonzeros(iyv)) ;
+it_ = MaxLag + 1 ;
+
+if exo_nbr == 0
+    oo_.exo_steady_state = [] ;
+end
+[junk,jacobia_] = feval([M_.fname '_dynamic'],z, [oo_.exo_simul ...
+                    oo_.exo_det_simul], M_.params, zeros(endo_nbr,1), it_);
+if any(junk~=0)
+    error(['discretionary_policy: the model must be written in deviation ' ...
+           'form and not have constant terms'])
+end
+
+eq_nbr= size(jacobia_,1);
+instr_nbr=endo_nbr-eq_nbr;
+
+instr_id=nan(instr_nbr,1);
+for j=1:instr_nbr
+	vj=deblank(Instruments(j,:));
+	vj_id=strmatch(vj,endo_names,'exact');
+	if ~isempty(vj_id)
+		instr_id(j)=vj_id;
+	else
+		error([mfilename,':: instrument ',vj,' not found'])
+	end
+end
+
+Indices={'lag','0','lead'};
+iter=1;
+for j=1:numel(Indices)
+    eval(['A',Indices{j},'=zeros(eq_nbr,endo_nbr);'])
+	if strcmp(Indices{j},'0')||(strcmp(Indices{j},'lag') && MaxLag)||(strcmp(Indices{j},'lead') && MaxLead)
+	    [junk,row,col]=find(lead_lag_incidence(iter,:));
+	    eval(['A',Indices{j},'(:,row)=jacobia_(:,col);'])
+		iter=iter+1;
+	end
+end
+B=jacobia_(:,nnz(iyv)+1:end);
+
+%%% MAIN ENGINE %%%
+qz_criterium = options_.qz_criterium;
+solve_maxit = options_.solve_maxit;
+discretion_tol = options_.discretionary_tol;
+
+if ~isempty(Hold)
+	[H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium,Hold);
+else
+	[H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium);
+end
+
+if info
+    dr=[];
+    return
+else
+	Hold=H;
+	% Hold=[]; use this line if persistent command is not used.
+end
+% update the following elements
+
+LLI=lead_lag_incidence;
+LLI(MaxLag,:)=any(H);
+
+LLI=LLI';
+tmp=find(LLI);
+LLI(tmp)=1:numel(tmp);
+
+M_.lead_lag_incidence = LLI';
+
+% set the state
+dr=oo_.dr;
+dr.ys =zeros(endo_nbr,1);
+dr=set_state_space(dr,M_);
+order_var=dr.order_var;
+
+T=H(order_var,order_var);
+dr.ghu=G(order_var,:);
+Selection=any(T);
+dr.ghx=T(:,Selection);
+
+ys=NondistortionarySteadyState(M_);
+dr.ys=ys; % <--- dr.ys =zeros(NewEndo_nbr,1);
+
+function ys=NondistortionarySteadyState(M_)
+if exist([M_.fname,'_steadystate.m'],'file')
+	eval(['ys=',M_.fname,'_steadystate.m;'])
+else
+	ys=zeros(M_.endo_nbr,1);
+end
diff --git a/matlab/discretionary_policy_engine.m b/matlab/discretionary_policy_engine.m
index c59b24dcd8..9b94d7301b 100644
--- a/matlab/discretionary_policy_engine.m
+++ b/matlab/discretionary_policy_engine.m
@@ -1,299 +1,299 @@
-function [H,G,retcode]=discretionary_policy_engine(AAlag,AA0,AAlead,BB,bigw,instr_id,beta,solve_maxit,discretion_tol,qz_criterium,H00,verbose)
-
-% Solves the discretionary problem for a model of the form:
-% AAlag*yy_{t-1}+AA0*yy_t+AAlead*yy_{t+1}+BB*e=0, with W the weight on the
-% variables in vector y_t and instr_id is the location of the instruments
-% in the yy_t vector.
-% We use the Dennis (2007, Macroeconomic Dynamics) algorithm and so we need
-% to re-write the model in the form
-%  A0*y_t=A1*y_{t-1}+A2*y_{t+1}+A3*x_t+A4*x_{t+1}+A5*e_t, with W the
-% weight on the y_t vector and Q the weight on the x_t vector of
-% instruments.
-
-% Copyright (C) 2007-2012 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/>.
-
-if nargin<12
-    verbose=0;
-    if nargin<11
-        H00=[];
-        if nargin<10
-            qz_criterium=1.000001;
-            if nargin<9
-                discretion_tol=sqrt(eps);
-                if nargin<8
-                    solve_maxit=3000;
-                    if nargin<7
-                        beta=.99;
-                        if nargin<6
-                            error([mfilename,':: Insufficient number of input arguments'])
-                        elseif nargin>12
-                            error([mfilename,':: Number of input arguments cannot exceed 12'])
-                        end
-                    end
-                end
-            end
-        end
-    end
-end
-
-[A0,A1,A2,A3,A4,A5,W,Q,endo_nbr,exo_nbr,aux,endo_augm_id]=GetDennisMatrices(AAlag,AA0,AAlead,BB,bigw,instr_id);
-% aux is a logical index of the instruments which appear with lags in the
-% model. Their location in the state vector is instr_id(aux)
-% endo_augm_id is index (not logical) of locations of the augmented vector
-% of non-instrumental variables
-
-AuxiliaryVariables_nbr=sum(aux);
-H0=zeros(endo_nbr+AuxiliaryVariables_nbr);
-if ~isempty(H00)
-    H0(1:endo_nbr,1:endo_nbr)=H00;clear H00
-end
-
-H10=H0(endo_augm_id,endo_augm_id);
-F10=H0(instr_id,endo_augm_id);
-
-iter=0;
-H1=H10;
-F1=F10;
-while 1
-    iter=iter+1;
-    P=SylvesterDoubling(W+beta*F1'*Q*F1,beta*H1',H1,discretion_tol,solve_maxit);
-    if any(any(isnan(P)))
-        P=SylvesterHessenbergSchur(W+beta*F1'*Q*F1,beta*H1',H1);
-        if any(any(isnan(P)))
-            retcode=2;
-            return
-        end
-    end
-    D=A0-A2*H1-A4*F1;
-    Dinv=inv(D);
-    A3DPD=A3'*Dinv'*P*Dinv;
-    F1=-(Q+A3DPD*A3)\(A3DPD*A1);
-    H1=Dinv*(A1+A3*F1);
-    
-    [rcode,NQ]=CheckConvergence([H1;F1]-[H10;F10],iter,solve_maxit,discretion_tol);
-    if rcode
-        break
-    else
-        if verbose
-            disp(NQ)
-        end
-    end
-    H10=H1;
-    F10=F1;
-end
-
-retcode = 0;
-switch rcode
-  case 3 % nan
-    retcode=63;
-    retcode(2)=10000;
-    if verbose
-        disp([mfilename,':: NAN elements in the solution'])
-    end
-  case 2% maxiter
-    retcode = 61
-    if verbose
-        disp([mfilename,':: Maximum Number of Iterations reached'])
-    end
-  case 1
-    BadEig=max(abs(eig(H1)))>qz_criterium;
-    if BadEig
-        retcode=62;
-        retcode(2)=100*max(abs(eig(H1)));
-        if verbose
-            disp([mfilename,':: Some eigenvalues greater than qz_criterium, Model potentially unstable'])
-        end
-    end
-end
-
-if retcode(1)
-    H=[];
-    G=[];
-else
-    F2=-(Q+A3DPD*A3)\(A3DPD*A5);
-    H2=Dinv*(A5+A3*F2);
-    H=zeros(endo_nbr+AuxiliaryVariables_nbr);
-    G=zeros(endo_nbr+AuxiliaryVariables_nbr,exo_nbr);
-    H(endo_augm_id,endo_augm_id)=H1;
-    H(instr_id,endo_augm_id)=F1;
-    G(endo_augm_id,:)=H2;
-    G(instr_id,:)=F2;
-    
-    % Account for auxilliary variables
-    H(:,instr_id(aux))=H(:,end-(AuxiliaryVariables_nbr-1:-1:0));
-    H=H(1:endo_nbr,1:endo_nbr);
-    G=G(1:endo_nbr,:);
-end
-
-end
-
-
-function [rcode,NQ]=CheckConvergence(Q,iter,MaxIter,crit)
-
-NQ=max(max(abs(Q)));% norm(Q); seems too costly
-if isnan(NQ)
-    rcode=3;
-elseif iter>MaxIter;
-    rcode=2;
-elseif NQ<crit
-    rcode=1;
-else
-    rcode=0;
-end
-
-end
-
-function [A00,A11,A22,A33,A44,A55,WW,Q,endo_nbr,exo_nbr,aux,endo_augm_id]=GetDennisMatrices(AAlag,AA0,AAlead,BB,bigw,instr_id)
-[eq_nbr,endo_nbr]=size(AAlag);
-exo_nbr=size(BB,2);
-y=setdiff(1:endo_nbr,instr_id);
-instr_nbr=numel(instr_id);
-
-A0=AA0(:,y);
-A1=-AAlag(:,y);
-A2=-AAlead(:,y);
-A3=-AA0(:,instr_id);
-A4=-AAlead(:,instr_id);
-A5=-BB;
-W=bigw(y,y);
-Q=bigw(instr_id,instr_id);
-% Adjust for possible lags in instruments by creating auxiliary equations
-A6=-AAlag(:,instr_id);
-aux=any(A6);
-AuxiliaryVariables_nbr=sum(aux);
-ny=eq_nbr;
-m=eq_nbr+AuxiliaryVariables_nbr;
-A00=zeros(m);A00(1:ny,1:ny)=A0;A00(ny+1:end,ny+1:end)=eye(AuxiliaryVariables_nbr);
-A11=zeros(m);A11(1:ny,1:ny)=A1;A11(1:ny,ny+1:end)=A6(:,aux);
-A22=zeros(m);A22(1:ny,1:ny)=A2;
-A33=zeros(m,instr_nbr);A33(1:ny,1:end)=A3;A33(ny+1:end,aux)=eye(AuxiliaryVariables_nbr);
-A44=zeros(m,instr_nbr);A44(1:ny,1:end)=A4;
-A55=zeros(m,exo_nbr);A55(1:ny,1:end)=A5;
-WW=zeros(m);WW(1:ny,1:ny)=W;
-endo_augm_id=setdiff(1:endo_nbr+AuxiliaryVariables_nbr,instr_id);
-
-end
-
-function v= SylvesterDoubling (d,g,h,tol,maxit)
-
-% DOUBLES  Solves a Sylvester equation using doubling
-%
-%  [v,info] = doubles (g,d,h,tol,maxit)  uses a doubling algorithm
-%   to solve the  Sylvester equation v  = d + g v h
-
-v = d;
-for i =1:maxit,
-    vadd = g*v*h;
-    v = v+vadd;
-    if norm (vadd,1) <= (tol*norm(v,1))
-        break;
-    end
-    g = g*g;
-    h = h*h;
-end
-
-end
-
-function v = SylvesterHessenbergSchur(d,g,h)
-%
-% DSYLHS  Solves a discrete time sylvester equation	 using the
-% Hessenberg-Schur algorithm
-%
-% v = DSYLHS(g,d,h) computes the matrix v that satisfies the
-% discrete time sylvester equation
-%
-%           v = d + g'vh
-
-if size(g,1) >= size(h,1)
-    [u,gbarp] = hess(g');
-    [t,hbar] = schur(h);
-    [vbar] = sylvest_private(gbarp,u'*d*t,hbar,1e-15);
-    v = u*vbar*t';
-else
-    [u,gbar] = schur(g);
-    [t,hbarp] = hess(h');
-    [vbar] = sylvest_private(hbarp,t'*d'*u,gbar,1e-15);
-    v = u*vbar'*t';
-end
-
-end
-
-
-function v = sylvest_private(g,d,h,tol)
-%
-% SYLVEST  Solves a Sylvester equation
-%
-%  solves the Sylvester equation
-%         v = d + g v h
-%  for v where both g and h must be  upper block triangular.
-%  The output info is zero on a successful return.
-%  The input tol indicates when an element of g or h should be considered
-%  zero.
-
-[m,n] = size(d);
-v = zeros(m,n);
-w = eye(m);
-i = 1;
-temp = [];
-
-%First handle the i = 1 case outside the loop
-
-if i< n,
-    if abs(h(i+1,i)) < tol,
-        v(:,i)= (w - g*h(i,i))\d(:,i);
-        i = i+1;
-    else
-        A = [w-g*h(i,i)     (-g*h(i+1,i));...
-            -g*h(i,i+1)    w-g*h(i+1,i+1)];
-        C = [d(:,i); d(:,i+1)];
-        X = A\C;
-        v(:,i) = X(1:m,:);
-        v(:,i+1) = X(m+1:2*m,  :);
-        i = i+2;
-    end
-end
-
-%Handle the rest of the matrix with the possible exception of i=n
-
-while i<n,
-    b= i-1;
-    temp = [temp g*v(:,size(temp,2)+1:b)]; %#ok<AGROW>
-    if abs(h(i+1,i)) < tol,
-        v(:,i) = (w - g*h(i,i))\(d(:,i) + temp*h(1:b,i));
-        i = i+1;
-    else
-        A = [w - g*h(i,i)    (-g*h(i+1,i));   ...
-            -g*h(i,i+1)    w - g*h(i+1,i+1)];
-        C = [d(:,i) + temp*h(1:b,i);         ...
-            d(:,i+1) + temp*h(1:b,i+1)];
-        X = A\C;
-        v(:,i) = X(1:m,:);
-        v(:,i+1) = X(m+1:2*m, :);
-        i = i+2;
-    end
-end
-
-%Handle the i = n case if i=n was not in a 2-2 block
-
-if i==n,
-    b = i-1;
-    temp = [temp g*v(:,size(temp,2)+1:b)];
-    v(:,i) = (w-g*h(i,i))\(d(:,i) + temp*h(1:b,i));
-end
-
-end
+function [H,G,retcode]=discretionary_policy_engine(AAlag,AA0,AAlead,BB,bigw,instr_id,beta,solve_maxit,discretion_tol,qz_criterium,H00,verbose)
+
+% Solves the discretionary problem for a model of the form:
+% AAlag*yy_{t-1}+AA0*yy_t+AAlead*yy_{t+1}+BB*e=0, with W the weight on the
+% variables in vector y_t and instr_id is the location of the instruments
+% in the yy_t vector.
+% We use the Dennis (2007, Macroeconomic Dynamics) algorithm and so we need
+% to re-write the model in the form
+%  A0*y_t=A1*y_{t-1}+A2*y_{t+1}+A3*x_t+A4*x_{t+1}+A5*e_t, with W the
+% weight on the y_t vector and Q the weight on the x_t vector of
+% instruments.
+
+% Copyright (C) 2007-2012 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/>.
+
+if nargin<12
+    verbose=0;
+    if nargin<11
+        H00=[];
+        if nargin<10
+            qz_criterium=1.000001;
+            if nargin<9
+                discretion_tol=sqrt(eps);
+                if nargin<8
+                    solve_maxit=3000;
+                    if nargin<7
+                        beta=.99;
+                        if nargin<6
+                            error([mfilename,':: Insufficient number of input arguments'])
+                        elseif nargin>12
+                            error([mfilename,':: Number of input arguments cannot exceed 12'])
+                        end
+                    end
+                end
+            end
+        end
+    end
+end
+
+[A0,A1,A2,A3,A4,A5,W,Q,endo_nbr,exo_nbr,aux,endo_augm_id]=GetDennisMatrices(AAlag,AA0,AAlead,BB,bigw,instr_id);
+% aux is a logical index of the instruments which appear with lags in the
+% model. Their location in the state vector is instr_id(aux)
+% endo_augm_id is index (not logical) of locations of the augmented vector
+% of non-instrumental variables
+
+AuxiliaryVariables_nbr=sum(aux);
+H0=zeros(endo_nbr+AuxiliaryVariables_nbr);
+if ~isempty(H00)
+    H0(1:endo_nbr,1:endo_nbr)=H00;clear H00
+end
+
+H10=H0(endo_augm_id,endo_augm_id);
+F10=H0(instr_id,endo_augm_id);
+
+iter=0;
+H1=H10;
+F1=F10;
+while 1
+    iter=iter+1;
+    P=SylvesterDoubling(W+beta*F1'*Q*F1,beta*H1',H1,discretion_tol,solve_maxit);
+    if any(any(isnan(P)))
+        P=SylvesterHessenbergSchur(W+beta*F1'*Q*F1,beta*H1',H1);
+        if any(any(isnan(P)))
+            retcode=2;
+            return
+        end
+    end
+    D=A0-A2*H1-A4*F1;
+    Dinv=inv(D);
+    A3DPD=A3'*Dinv'*P*Dinv;
+    F1=-(Q+A3DPD*A3)\(A3DPD*A1);
+    H1=Dinv*(A1+A3*F1);
+    
+    [rcode,NQ]=CheckConvergence([H1;F1]-[H10;F10],iter,solve_maxit,discretion_tol);
+    if rcode
+        break
+    else
+        if verbose
+            disp(NQ)
+        end
+    end
+    H10=H1;
+    F10=F1;
+end
+
+retcode = 0;
+switch rcode
+  case 3 % nan
+    retcode=63;
+    retcode(2)=10000;
+    if verbose
+        disp([mfilename,':: NAN elements in the solution'])
+    end
+  case 2% maxiter
+    retcode = 61
+    if verbose
+        disp([mfilename,':: Maximum Number of Iterations reached'])
+    end
+  case 1
+    BadEig=max(abs(eig(H1)))>qz_criterium;
+    if BadEig
+        retcode=62;
+        retcode(2)=100*max(abs(eig(H1)));
+        if verbose
+            disp([mfilename,':: Some eigenvalues greater than qz_criterium, Model potentially unstable'])
+        end
+    end
+end
+
+if retcode(1)
+    H=[];
+    G=[];
+else
+    F2=-(Q+A3DPD*A3)\(A3DPD*A5);
+    H2=Dinv*(A5+A3*F2);
+    H=zeros(endo_nbr+AuxiliaryVariables_nbr);
+    G=zeros(endo_nbr+AuxiliaryVariables_nbr,exo_nbr);
+    H(endo_augm_id,endo_augm_id)=H1;
+    H(instr_id,endo_augm_id)=F1;
+    G(endo_augm_id,:)=H2;
+    G(instr_id,:)=F2;
+    
+    % Account for auxilliary variables
+    H(:,instr_id(aux))=H(:,end-(AuxiliaryVariables_nbr-1:-1:0));
+    H=H(1:endo_nbr,1:endo_nbr);
+    G=G(1:endo_nbr,:);
+end
+
+end
+
+
+function [rcode,NQ]=CheckConvergence(Q,iter,MaxIter,crit)
+
+NQ=max(max(abs(Q)));% norm(Q); seems too costly
+if isnan(NQ)
+    rcode=3;
+elseif iter>MaxIter;
+    rcode=2;
+elseif NQ<crit
+    rcode=1;
+else
+    rcode=0;
+end
+
+end
+
+function [A00,A11,A22,A33,A44,A55,WW,Q,endo_nbr,exo_nbr,aux,endo_augm_id]=GetDennisMatrices(AAlag,AA0,AAlead,BB,bigw,instr_id)
+[eq_nbr,endo_nbr]=size(AAlag);
+exo_nbr=size(BB,2);
+y=setdiff(1:endo_nbr,instr_id);
+instr_nbr=numel(instr_id);
+
+A0=AA0(:,y);
+A1=-AAlag(:,y);
+A2=-AAlead(:,y);
+A3=-AA0(:,instr_id);
+A4=-AAlead(:,instr_id);
+A5=-BB;
+W=bigw(y,y);
+Q=bigw(instr_id,instr_id);
+% Adjust for possible lags in instruments by creating auxiliary equations
+A6=-AAlag(:,instr_id);
+aux=any(A6);
+AuxiliaryVariables_nbr=sum(aux);
+ny=eq_nbr;
+m=eq_nbr+AuxiliaryVariables_nbr;
+A00=zeros(m);A00(1:ny,1:ny)=A0;A00(ny+1:end,ny+1:end)=eye(AuxiliaryVariables_nbr);
+A11=zeros(m);A11(1:ny,1:ny)=A1;A11(1:ny,ny+1:end)=A6(:,aux);
+A22=zeros(m);A22(1:ny,1:ny)=A2;
+A33=zeros(m,instr_nbr);A33(1:ny,1:end)=A3;A33(ny+1:end,aux)=eye(AuxiliaryVariables_nbr);
+A44=zeros(m,instr_nbr);A44(1:ny,1:end)=A4;
+A55=zeros(m,exo_nbr);A55(1:ny,1:end)=A5;
+WW=zeros(m);WW(1:ny,1:ny)=W;
+endo_augm_id=setdiff(1:endo_nbr+AuxiliaryVariables_nbr,instr_id);
+
+end
+
+function v= SylvesterDoubling (d,g,h,tol,maxit)
+
+% DOUBLES  Solves a Sylvester equation using doubling
+%
+%  [v,info] = doubles (g,d,h,tol,maxit)  uses a doubling algorithm
+%   to solve the  Sylvester equation v  = d + g v h
+
+v = d;
+for i =1:maxit,
+    vadd = g*v*h;
+    v = v+vadd;
+    if norm (vadd,1) <= (tol*norm(v,1))
+        break;
+    end
+    g = g*g;
+    h = h*h;
+end
+
+end
+
+function v = SylvesterHessenbergSchur(d,g,h)
+%
+% DSYLHS  Solves a discrete time sylvester equation	 using the
+% Hessenberg-Schur algorithm
+%
+% v = DSYLHS(g,d,h) computes the matrix v that satisfies the
+% discrete time sylvester equation
+%
+%           v = d + g'vh
+
+if size(g,1) >= size(h,1)
+    [u,gbarp] = hess(g');
+    [t,hbar] = schur(h);
+    [vbar] = sylvest_private(gbarp,u'*d*t,hbar,1e-15);
+    v = u*vbar*t';
+else
+    [u,gbar] = schur(g);
+    [t,hbarp] = hess(h');
+    [vbar] = sylvest_private(hbarp,t'*d'*u,gbar,1e-15);
+    v = u*vbar'*t';
+end
+
+end
+
+
+function v = sylvest_private(g,d,h,tol)
+%
+% SYLVEST  Solves a Sylvester equation
+%
+%  solves the Sylvester equation
+%         v = d + g v h
+%  for v where both g and h must be  upper block triangular.
+%  The output info is zero on a successful return.
+%  The input tol indicates when an element of g or h should be considered
+%  zero.
+
+[m,n] = size(d);
+v = zeros(m,n);
+w = eye(m);
+i = 1;
+temp = [];
+
+%First handle the i = 1 case outside the loop
+
+if i< n,
+    if abs(h(i+1,i)) < tol,
+        v(:,i)= (w - g*h(i,i))\d(:,i);
+        i = i+1;
+    else
+        A = [w-g*h(i,i)     (-g*h(i+1,i));...
+            -g*h(i,i+1)    w-g*h(i+1,i+1)];
+        C = [d(:,i); d(:,i+1)];
+        X = A\C;
+        v(:,i) = X(1:m,:);
+        v(:,i+1) = X(m+1:2*m,  :);
+        i = i+2;
+    end
+end
+
+%Handle the rest of the matrix with the possible exception of i=n
+
+while i<n,
+    b= i-1;
+    temp = [temp g*v(:,size(temp,2)+1:b)]; %#ok<AGROW>
+    if abs(h(i+1,i)) < tol,
+        v(:,i) = (w - g*h(i,i))\(d(:,i) + temp*h(1:b,i));
+        i = i+1;
+    else
+        A = [w - g*h(i,i)    (-g*h(i+1,i));   ...
+            -g*h(i,i+1)    w - g*h(i+1,i+1)];
+        C = [d(:,i) + temp*h(1:b,i);         ...
+            d(:,i+1) + temp*h(1:b,i+1)];
+        X = A\C;
+        v(:,i) = X(1:m,:);
+        v(:,i+1) = X(m+1:2*m, :);
+        i = i+2;
+    end
+end
+
+%Handle the i = n case if i=n was not in a 2-2 block
+
+if i==n,
+    b = i-1;
+    temp = [temp g*v(:,size(temp,2)+1:b)];
+    v(:,i) = (w-g*h(i,i))\(d(:,i) + temp*h(1:b,i));
+end
+
+end
diff --git a/matlab/ident_bruteforce.m b/matlab/ident_bruteforce.m
index 7f1e84485c..344fd408d3 100644
--- a/matlab/ident_bruteforce.m
+++ b/matlab/ident_bruteforce.m
@@ -1,102 +1,102 @@
-function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)
-% function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)
-%
-% given the Jacobian matrix J of moment derivatives w.r.t. parameters
-% computes, for  each column of  J, the groups of columns from 1 to n that
-% can repliate at best the derivatives of that column
-%
-% OUTPUTS
-%  pars  : cell array with groupf of params for each column of J for 1 to n
-%  cosnJ : the cosn of each column with the selected group of columns
-
-% Copyright (C) 2009-2011 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/licen
-global M_ options_
-
-OutputDirectoryName = CheckPath('Identification',M_.dname);
-
-k = size(J,2); % number of parameters
-
-if nargin<2 || isempty(n)
-    n = 4; % max n-tuple
-end
-if nargin<3 || isempty(TeX)
-    TeX = 0; % max n-tuple
-end
-
-cosnJ=zeros(k,n);
-pars{k,n}=[];
-for ll = 1:n,
-    h = dyn_waitbar(0,['Brute force collinearity for ' int2str(ll) ' parameters.']);
-    for ii = 1:k
-        tmp = find([1:k]~=ii);
-        tmp2  = nchoosek(tmp,ll);
-        cosnJ2=zeros(size(tmp2,1),1);
-        b=[];
-        for jj = 1:size(tmp2,1)
-            [cosnJ2(jj,1), b(:,jj)] = cosn([J(:,ii),J(:,tmp2(jj,:))]);
-        end
-        cosnJ(ii,ll) = max(cosnJ2(:,1));
-        if cosnJ(ii,ll)>1.e-8,
-            if ll>1 && ((cosnJ(ii,ll)-cosnJ(ii,ll-1))<1.e-8),
-                pars{ii,ll} = [pars{ii,ll-1} NaN];
-                cosnJ(ii,ll) = cosnJ(ii,ll-1);
-            else
-                pars{ii,ll} = tmp2(find(cosnJ2(:,1)==max(cosnJ2(:,1))),:);
-            end
-        else
-            pars{ii,ll} = NaN(1,ll);
-        end
-        dyn_waitbar(ii/k,h)
-    end
-    dyn_waitbar_close(h);
-    if TeX
-        filename = [OutputDirectoryName '/' M_.fname '_collinearity_patterns' int2str(ll) '.TeX'];
-        fidTeX = fopen(filename,'w');
-        fprintf(fidTeX,'%% TeX-table generated by ident_bruteforce (Dynare).\n');
-        fprintf(fidTeX,['%% Collinearity patterns with ',int2str(ll),' parameter(s)\n']);
-        fprintf(fidTeX,['%% ' datestr(now,0)]);
-        fprintf(fidTeX,' \n');
-        fprintf(fidTeX,' \n');
-        fprintf(fidTeX,'{\\tiny \n');
-        fprintf(fidTeX,'\\begin{table}\n');
-        fprintf(fidTeX,'\\centering\n');
-        fprintf(fidTeX,'\\begin{tabular}{l|lc} \n');
-        fprintf(fidTeX,'\\hline\\hline \\\\ \n');
-        fprintf(fidTeX,'  Parameter & Explanatory & cosn \\\\ \n');
-        fprintf(fidTeX,'            & parameter(s)   &  \\\\ \n');
-        fprintf(fidTeX,'\\hline \\\\ \n');
-        for i=1:k,
-            plist='';
-            for ii=1:ll,
-                plist = [plist ' $' pnames_TeX(pars{i,ll}(ii),:) '$ '];
-            end
-            fprintf(fidTeX,'$%s$ & [%s] & %7.3f \\\\ \n',...
-                pnames_TeX(i,:),...
-                plist,...
-                cosnJ(i,ll));
-        end
-        fprintf(fidTeX,'\\hline\\hline \n');
-        fprintf(fidTeX,'\\end{tabular}\n ');
-        fprintf(fidTeX,['\\caption{Collinearity patterns with ',int2str(ll),' parameter(s)}\n ']);
-        fprintf(fidTeX,['\\label{Table:CollinearityPatterns:',int2str(ll),'}\n']);
-        fprintf(fidTeX,'\\end{table}\n');
-        fprintf(fidTeX,'} \n');
-        fprintf(fidTeX,'%% End of TeX file.\n');
-        fclose(fidTeX);
-    end
+function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)
+% function [pars, cosnJ] = ident_bruteforce(J,n,TeX, pnames_TeX)
+%
+% given the Jacobian matrix J of moment derivatives w.r.t. parameters
+% computes, for  each column of  J, the groups of columns from 1 to n that
+% can repliate at best the derivatives of that column
+%
+% OUTPUTS
+%  pars  : cell array with groupf of params for each column of J for 1 to n
+%  cosnJ : the cosn of each column with the selected group of columns
+
+% Copyright (C) 2009-2011 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/licen
+global M_ options_
+
+OutputDirectoryName = CheckPath('Identification',M_.dname);
+
+k = size(J,2); % number of parameters
+
+if nargin<2 || isempty(n)
+    n = 4; % max n-tuple
+end
+if nargin<3 || isempty(TeX)
+    TeX = 0; % max n-tuple
+end
+
+cosnJ=zeros(k,n);
+pars{k,n}=[];
+for ll = 1:n,
+    h = dyn_waitbar(0,['Brute force collinearity for ' int2str(ll) ' parameters.']);
+    for ii = 1:k
+        tmp = find([1:k]~=ii);
+        tmp2  = nchoosek(tmp,ll);
+        cosnJ2=zeros(size(tmp2,1),1);
+        b=[];
+        for jj = 1:size(tmp2,1)
+            [cosnJ2(jj,1), b(:,jj)] = cosn([J(:,ii),J(:,tmp2(jj,:))]);
+        end
+        cosnJ(ii,ll) = max(cosnJ2(:,1));
+        if cosnJ(ii,ll)>1.e-8,
+            if ll>1 && ((cosnJ(ii,ll)-cosnJ(ii,ll-1))<1.e-8),
+                pars{ii,ll} = [pars{ii,ll-1} NaN];
+                cosnJ(ii,ll) = cosnJ(ii,ll-1);
+            else
+                pars{ii,ll} = tmp2(find(cosnJ2(:,1)==max(cosnJ2(:,1))),:);
+            end
+        else
+            pars{ii,ll} = NaN(1,ll);
+        end
+        dyn_waitbar(ii/k,h)
+    end
+    dyn_waitbar_close(h);
+    if TeX
+        filename = [OutputDirectoryName '/' M_.fname '_collinearity_patterns' int2str(ll) '.TeX'];
+        fidTeX = fopen(filename,'w');
+        fprintf(fidTeX,'%% TeX-table generated by ident_bruteforce (Dynare).\n');
+        fprintf(fidTeX,['%% Collinearity patterns with ',int2str(ll),' parameter(s)\n']);
+        fprintf(fidTeX,['%% ' datestr(now,0)]);
+        fprintf(fidTeX,' \n');
+        fprintf(fidTeX,' \n');
+        fprintf(fidTeX,'{\\tiny \n');
+        fprintf(fidTeX,'\\begin{table}\n');
+        fprintf(fidTeX,'\\centering\n');
+        fprintf(fidTeX,'\\begin{tabular}{l|lc} \n');
+        fprintf(fidTeX,'\\hline\\hline \\\\ \n');
+        fprintf(fidTeX,'  Parameter & Explanatory & cosn \\\\ \n');
+        fprintf(fidTeX,'            & parameter(s)   &  \\\\ \n');
+        fprintf(fidTeX,'\\hline \\\\ \n');
+        for i=1:k,
+            plist='';
+            for ii=1:ll,
+                plist = [plist ' $' pnames_TeX(pars{i,ll}(ii),:) '$ '];
+            end
+            fprintf(fidTeX,'$%s$ & [%s] & %7.3f \\\\ \n',...
+                pnames_TeX(i,:),...
+                plist,...
+                cosnJ(i,ll));
+        end
+        fprintf(fidTeX,'\\hline\\hline \n');
+        fprintf(fidTeX,'\\end{tabular}\n ');
+        fprintf(fidTeX,['\\caption{Collinearity patterns with ',int2str(ll),' parameter(s)}\n ']);
+        fprintf(fidTeX,['\\label{Table:CollinearityPatterns:',int2str(ll),'}\n']);
+        fprintf(fidTeX,'\\end{table}\n');
+        fprintf(fidTeX,'} \n');
+        fprintf(fidTeX,'%% End of TeX file.\n');
+        fclose(fidTeX);
+    end
 end
\ No newline at end of file
diff --git a/mex/sources/estimation/tests/DsgeLikelihood.m b/mex/sources/estimation/tests/DsgeLikelihood.m
index a22501b587..6de151c6d8 100644
--- a/mex/sources/estimation/tests/DsgeLikelihood.m
+++ b/mex/sources/estimation/tests/DsgeLikelihood.m
@@ -1,345 +1,345 @@
-function [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations)
-% function [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations)
-% Evaluates the posterior kernel of a dsge model. 
-% 
-% INPUTS 
-%   xparam1                        [double]   vector of model parameters.
-%   gend                           [integer]  scalar specifying the number of observations.
-%   data                           [double]   matrix of data
-%   data_index                     [cell]     cell of column vectors
-%   number_of_observations         [integer]
-%   no_more_missing_observations   [integer] 
-% OUTPUTS 
-%   fval        :     value of the posterior kernel at xparam1.
-%   cost_flag   :     zero if the function returns a penalty, one otherwise.
-%   ys          :     steady state of original endogenous variables
-%   trend_coeff :
-%   info        :     vector of informations about the penalty:
-%                     41: one (many) parameter(s) do(es) not satisfied the lower bound
-%                     42: one (many) parameter(s) do(es) not satisfied the upper bound
-%               
-% SPECIAL REQUIREMENTS
-%
-
-% Copyright (C) 2004-2010 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/>.
-
-global bayestopt_ estim_params_ options_ trend_coeff_ M_ oo_
-fval            = [];
-ys              = [];
-trend_coeff     = [];
-cost_flag       = 1;
-nobs            = size(options_.varobs,1);
-%------------------------------------------------------------------------------
-% 1. Get the structural parameters & define penalties
-%------------------------------------------------------------------------------
-if options_.mode_compute ~= 1 & any(xparam1 < bayestopt_.lb)
-    k = find(xparam1 < bayestopt_.lb);
-    fval = bayestopt_.penalty+sum((bayestopt_.lb(k)-xparam1(k)).^2);
-    cost_flag = 0;
-    info = 41;
-    return;
-end
-if options_.mode_compute ~= 1 & any(xparam1 > bayestopt_.ub)
-    k = find(xparam1 > bayestopt_.ub);
-    fval = bayestopt_.penalty+sum((xparam1(k)-bayestopt_.ub(k)).^2);
-    cost_flag = 0;
-    info = 42;
-    return;
-end
-Q = M_.Sigma_e;
-H = M_.H;
-for i=1:estim_params_.nvx
-    k =estim_params_.var_exo(i,1);
-    Q(k,k) = xparam1(i)*xparam1(i);
-end
-offset = estim_params_.nvx;
-if estim_params_.nvn
-    for i=1:estim_params_.nvn
-        k = estim_params_.var_endo(i,1);
-        H(k,k) = xparam1(i+offset)*xparam1(i+offset);
-    end
-    offset = offset+estim_params_.nvn;
-end
-if estim_params_.ncx
-    for i=1:estim_params_.ncx
-        k1 =estim_params_.corrx(i,1);
-        k2 =estim_params_.corrx(i,2);
-        Q(k1,k2) = xparam1(i+offset)*sqrt(Q(k1,k1)*Q(k2,k2));
-        Q(k2,k1) = Q(k1,k2);
-    end
-    [CholQ,testQ] = chol(Q);
-    if testQ    %% The variance-covariance matrix of the structural innovations is not definite positive.
-        %% We have to compute the eigenvalues of this matrix in order to build the penalty.
-        a = diag(eig(Q));
-        k = find(a < 0);
-        if k > 0
-            fval = bayestopt_.penalty+sum(-a(k));
-            cost_flag = 0;
-            info = 43;
-            return
-        end
-    end
-    offset = offset+estim_params_.ncx;
-end
-if estim_params_.ncn 
-    for i=1:estim_params_.ncn
-        k1 = options_.lgyidx2varobs(estim_params_.corrn(i,1));
-        k2 = options_.lgyidx2varobs(estim_params_.corrn(i,2));
-        H(k1,k2) = xparam1(i+offset)*sqrt(H(k1,k1)*H(k2,k2));
-        H(k2,k1) = H(k1,k2);
-    end
-    [CholH,testH] = chol(H);
-    if testH
-        a = diag(eig(H));
-        k = find(a < 0);
-        if k > 0
-            fval = bayestopt_.penalty+sum(-a(k));
-            cost_flag = 0;
-            info = 44;
-            return
-        end
-    end
-    offset = offset+estim_params_.ncn;
-end
-if estim_params_.np > 0
-    M_.params(estim_params_.param_vals(:,1)) = xparam1(offset+1:end);
-end
-M_.Sigma_e = Q;
-M_.H = H;
-%------------------------------------------------------------------------------
-% 2. call model setup & reduction program
-%------------------------------------------------------------------------------
-[T,R,SteadyState,info] = dynare_resolve(bayestopt_.restrict_var_list,...
-                                        bayestopt_.restrict_columns,...
-                                        bayestopt_.restrict_aux);
-if info(1) == 1 || info(1) == 2 || info(1) == 5
-    fval = bayestopt_.penalty+1;
-    cost_flag = 0;
-    return
-elseif info(1) == 3 || info(1) == 4 || info(1)==6 ||info(1) == 19 || info(1) == 20 || info(1) == 21
-    fval = bayestopt_.penalty+info(2);
-    cost_flag = 0;
-    return
-end
-bayestopt_.mf = bayestopt_.mf1;
-if options_.noconstant
-    constant = zeros(nobs,1);  
-else    
-    if options_.loglinear
-        constant = log(SteadyState(bayestopt_.mfys));
-    else
-        constant = SteadyState(bayestopt_.mfys);
-    end
-end
-if bayestopt_.with_trend
-    trend_coeff = zeros(nobs,1);
-    t = options_.trend_coeffs;
-    for i=1:length(t)
-        if ~isempty(t{i})
-            trend_coeff(i) = evalin('base',t{i});
-        end
-    end
-    trend = repmat(constant,1,gend)+trend_coeff*[1:gend];
-else
-    trend = repmat(constant,1,gend);
-end
-start = options_.presample+1;
-np    = size(T,1);
-mf    = bayestopt_.mf;
-no_missing_data_flag = (number_of_observations==gend*nobs);
-%------------------------------------------------------------------------------
-% 3. Initial condition of the Kalman filter
-%------------------------------------------------------------------------------
-T
-R
-Q
-R*Q*R'
-pause
-options_.lik_init = 1;
-kalman_algo = options_.kalman_algo;
-if options_.lik_init == 1               % Kalman filter
-    if kalman_algo ~= 2
-        kalman_algo = 1;
-    end
-    Pstar = lyapunov_symm(T,R*Q*R',options_.qz_criterium,options_.lyapunov_complex_threshold);
-    Pinf        = [];
-elseif options_.lik_init == 2   % Old Diffuse Kalman filter
-    if kalman_algo ~= 2
-        kalman_algo = 1;
-    end
-    Pstar = options_.Harvey_scale_factor*eye(np);
-    Pinf = [];
-elseif options_.lik_init == 3   % Diffuse Kalman filter
-    if kalman_algo ~= 4
-        kalman_algo = 3;
-    end
-    [QT,ST] = schur(T);
-    e1 = abs(ordeig(ST)) > 2-options_.qz_criterium;
-    [QT,ST] = ordschur(QT,ST,e1);
-    k = find(abs(ordeig(ST)) > 2-options_.qz_criterium);
-    nk = length(k);
-    nk1 = nk+1;
-    Pinf = zeros(np,np);
-    Pinf(1:nk,1:nk) = eye(nk);
-    Pstar = zeros(np,np);
-    B = QT'*R*Q*R'*QT;
-    for i=np:-1:nk+2
-        if ST(i,i-1) == 0
-            if i == np
-                c = zeros(np-nk,1);
-            else
-                c = ST(nk1:i,:)*(Pstar(:,i+1:end)*ST(i,i+1:end)')+...
-                    ST(i,i)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i);
-            end
-            q = eye(i-nk)-ST(nk1:i,nk1:i)*ST(i,i);
-            Pstar(nk1:i,i) = q\(B(nk1:i,i)+c);
-            Pstar(i,nk1:i-1) = Pstar(nk1:i-1,i)';
-        else
-            if i == np
-                c = zeros(np-nk,1);
-                c1 = zeros(np-nk,1);
-            else
-                c = ST(nk1:i,:)*(Pstar(:,i+1:end)*ST(i,i+1:end)')+...
-                    ST(i,i)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i)+...
-                    ST(i,i-1)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i-1);
-                c1 = ST(nk1:i,:)*(Pstar(:,i+1:end)*ST(i-1,i+1:end)')+...
-                     ST(i-1,i-1)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i-1)+...
-                     ST(i-1,i)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i);
-            end
-            q = [eye(i-nk)-ST(nk1:i,nk1:i)*ST(i,i) -ST(nk1:i,nk1:i)*ST(i,i-1);...
-                 -ST(nk1:i,nk1:i)*ST(i-1,i) eye(i-nk)-ST(nk1:i,nk1:i)*ST(i-1,i-1)];
-            z =  q\[B(nk1:i,i)+c;B(nk1:i,i-1)+c1];
-            Pstar(nk1:i,i) = z(1:(i-nk));
-            Pstar(nk1:i,i-1) = z(i-nk+1:end);
-            Pstar(i,nk1:i-1) = Pstar(nk1:i-1,i)';
-            Pstar(i-1,nk1:i-2) = Pstar(nk1:i-2,i-1)';
-            i = i - 1;
-        end
-    end
-    if i == nk+2
-        c = ST(nk+1,:)*(Pstar(:,nk+2:end)*ST(nk1,nk+2:end)')+ST(nk1,nk1)*ST(nk1,nk+2:end)*Pstar(nk+2:end,nk1);
-        Pstar(nk1,nk1)=(B(nk1,nk1)+c)/(1-ST(nk1,nk1)*ST(nk1,nk1));
-    end
-    Z = QT(mf,:);
-    R1 = QT'*R;
-    [QQ,RR,EE] = qr(Z*ST(:,1:nk),0);
-    k = find(abs(diag([RR; zeros(nk-size(Z,1),size(RR,2))])) < 1e-8);
-    if length(k) > 0
-        k1 = EE(:,k);
-        dd =ones(nk,1);
-        dd(k1) = zeros(length(k1),1);
-        Pinf(1:nk,1:nk) = diag(dd);
-    end
-end
-if kalman_algo == 2
-end
-kalman_tol = options_.kalman_tol;
-riccati_tol = options_.riccati_tol;
-mf = bayestopt_.mf1;
-Y   = data-trend;
-Pstar
-pause
-%------------------------------------------------------------------------------
-% 4. Likelihood evaluation
-%------------------------------------------------------------------------------
-if (kalman_algo==1)% Multivariate Kalman Filter
-    if no_missing_data_flag
-        LIK = kalman_filter(T,R,Q,H,Pstar,Y,start,mf,kalman_tol,riccati_tol); 
-    else
-        LIK = ...
-            missing_observations_kalman_filter(T,R,Q,H,Pstar,Y,start,mf,kalman_tol,riccati_tol, ...
-                                               data_index,number_of_observations,no_more_missing_observations);
-    end
-    if isinf(LIK)
-        kalman_algo = 2;
-    end
-end
-if (kalman_algo==2)% Univariate Kalman Filter
-    no_correlation_flag = 1;
-    if length(H)==1 & H == 0
-        H = zeros(nobs,1);
-    else
-        if all(all(abs(H-diag(diag(H)))<1e-14))% ie, the covariance matrix is diagonal...
-            H = diag(H);
-        else
-            no_correlation_flag = 0;
-        end
-    end
-    if no_correlation_flag
-        LIK = univariate_kalman_filter(T,R,Q,H,Pstar,Y,start,mf,kalman_tol,riccati_tol,data_index,number_of_observations,no_more_missing_observations);
-    else
-        LIK = univariate_kalman_filter_corr(T,R,Q,H,Pstar,Y,start,mf,kalman_tol,riccati_tol,data_index,number_of_observations,no_more_missing_observations);
-    end
-end
-if (kalman_algo==3)% Multivariate Diffuse Kalman Filter
-    if no_missing_data_flag
-        LIK = diffuse_kalman_filter(ST,R1,Q,H,Pinf,Pstar,Y,start,Z,kalman_tol, ...
-                                    riccati_tol);
-    else
-        LIK = missing_observations_diffuse_kalman_filter(ST,R1,Q,H,Pinf, ...
-                                                         Pstar,Y,start,Z,kalman_tol,riccati_tol,...
-                                                         data_index,number_of_observations,...
-                                                         no_more_missing_observations);
-    end
-    if isinf(LIK)
-        kalman_algo = 4;
-    end
-end
-if (kalman_algo==4)% Univariate Diffuse Kalman Filter
-    no_correlation_flag = 1;
-    if length(H)==1 & H == 0
-        H = zeros(nobs,1);
-    else
-        if all(all(abs(H-diag(diag(H)))<1e-14))% ie, the covariance matrix is diagonal...
-            H = diag(H);
-        else
-            no_correlation_flag = 0;
-        end
-    end
-    if no_correlation_flag
-        LIK = univariate_diffuse_kalman_filter(ST,R1,Q,H,Pinf,Pstar,Y, ...
-                                               start,Z,kalman_tol,riccati_tol,data_index,...
-                                               number_of_observations,no_more_missing_observations);
-    else
-        LIK = univariate_diffuse_kalman_filter_corr(ST,R1,Q,H,Pinf,Pstar, ...
-                                                    Y,start,Z,kalman_tol,riccati_tol,...
-                                                    data_index,number_of_observations,...
-                                                    no_more_missing_observations);
-    end
-end
-if isnan(LIK)
-    cost_flag = 0;
-    return
-end
-if imag(LIK)~=0
-    likelihood = bayestopt_.penalty;
-else
-    likelihood = LIK;
-end
-% ------------------------------------------------------------------------------
-% Adds prior if necessary
-% ------------------------------------------------------------------------------
-lnprior = priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7,bayestopt_.p3,bayestopt_.p4);
-fval    = (likelihood-lnprior);
-likelihood
-lnprior
-fval
-pause
-LIKDLL=logposterior(xparam1,Y,mexext)
-pause
-options_.kalman_algo = kalman_algo;
+function [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations)
+% function [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations)
+% Evaluates the posterior kernel of a dsge model. 
+% 
+% INPUTS 
+%   xparam1                        [double]   vector of model parameters.
+%   gend                           [integer]  scalar specifying the number of observations.
+%   data                           [double]   matrix of data
+%   data_index                     [cell]     cell of column vectors
+%   number_of_observations         [integer]
+%   no_more_missing_observations   [integer] 
+% OUTPUTS 
+%   fval        :     value of the posterior kernel at xparam1.
+%   cost_flag   :     zero if the function returns a penalty, one otherwise.
+%   ys          :     steady state of original endogenous variables
+%   trend_coeff :
+%   info        :     vector of informations about the penalty:
+%                     41: one (many) parameter(s) do(es) not satisfied the lower bound
+%                     42: one (many) parameter(s) do(es) not satisfied the upper bound
+%               
+% SPECIAL REQUIREMENTS
+%
+
+% Copyright (C) 2004-2010 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/>.
+
+global bayestopt_ estim_params_ options_ trend_coeff_ M_ oo_
+fval            = [];
+ys              = [];
+trend_coeff     = [];
+cost_flag       = 1;
+nobs            = size(options_.varobs,1);
+%------------------------------------------------------------------------------
+% 1. Get the structural parameters & define penalties
+%------------------------------------------------------------------------------
+if options_.mode_compute ~= 1 & any(xparam1 < bayestopt_.lb)
+    k = find(xparam1 < bayestopt_.lb);
+    fval = bayestopt_.penalty+sum((bayestopt_.lb(k)-xparam1(k)).^2);
+    cost_flag = 0;
+    info = 41;
+    return;
+end
+if options_.mode_compute ~= 1 & any(xparam1 > bayestopt_.ub)
+    k = find(xparam1 > bayestopt_.ub);
+    fval = bayestopt_.penalty+sum((xparam1(k)-bayestopt_.ub(k)).^2);
+    cost_flag = 0;
+    info = 42;
+    return;
+end
+Q = M_.Sigma_e;
+H = M_.H;
+for i=1:estim_params_.nvx
+    k =estim_params_.var_exo(i,1);
+    Q(k,k) = xparam1(i)*xparam1(i);
+end
+offset = estim_params_.nvx;
+if estim_params_.nvn
+    for i=1:estim_params_.nvn
+        k = estim_params_.var_endo(i,1);
+        H(k,k) = xparam1(i+offset)*xparam1(i+offset);
+    end
+    offset = offset+estim_params_.nvn;
+end
+if estim_params_.ncx
+    for i=1:estim_params_.ncx
+        k1 =estim_params_.corrx(i,1);
+        k2 =estim_params_.corrx(i,2);
+        Q(k1,k2) = xparam1(i+offset)*sqrt(Q(k1,k1)*Q(k2,k2));
+        Q(k2,k1) = Q(k1,k2);
+    end
+    [CholQ,testQ] = chol(Q);
+    if testQ    %% The variance-covariance matrix of the structural innovations is not definite positive.
+        %% We have to compute the eigenvalues of this matrix in order to build the penalty.
+        a = diag(eig(Q));
+        k = find(a < 0);
+        if k > 0
+            fval = bayestopt_.penalty+sum(-a(k));
+            cost_flag = 0;
+            info = 43;
+            return
+        end
+    end
+    offset = offset+estim_params_.ncx;
+end
+if estim_params_.ncn 
+    for i=1:estim_params_.ncn
+        k1 = options_.lgyidx2varobs(estim_params_.corrn(i,1));
+        k2 = options_.lgyidx2varobs(estim_params_.corrn(i,2));
+        H(k1,k2) = xparam1(i+offset)*sqrt(H(k1,k1)*H(k2,k2));
+        H(k2,k1) = H(k1,k2);
+    end
+    [CholH,testH] = chol(H);
+    if testH
+        a = diag(eig(H));
+        k = find(a < 0);
+        if k > 0
+            fval = bayestopt_.penalty+sum(-a(k));
+            cost_flag = 0;
+            info = 44;
+            return
+        end
+    end
+    offset = offset+estim_params_.ncn;
+end
+if estim_params_.np > 0
+    M_.params(estim_params_.param_vals(:,1)) = xparam1(offset+1:end);
+end
+M_.Sigma_e = Q;
+M_.H = H;
+%------------------------------------------------------------------------------
+% 2. call model setup & reduction program
+%------------------------------------------------------------------------------
+[T,R,SteadyState,info] = dynare_resolve(bayestopt_.restrict_var_list,...
+                                        bayestopt_.restrict_columns,...
+                                        bayestopt_.restrict_aux);
+if info(1) == 1 || info(1) == 2 || info(1) == 5
+    fval = bayestopt_.penalty+1;
+    cost_flag = 0;
+    return
+elseif info(1) == 3 || info(1) == 4 || info(1)==6 ||info(1) == 19 || info(1) == 20 || info(1) == 21
+    fval = bayestopt_.penalty+info(2);
+    cost_flag = 0;
+    return
+end
+bayestopt_.mf = bayestopt_.mf1;
+if options_.noconstant
+    constant = zeros(nobs,1);  
+else    
+    if options_.loglinear
+        constant = log(SteadyState(bayestopt_.mfys));
+    else
+        constant = SteadyState(bayestopt_.mfys);
+    end
+end
+if bayestopt_.with_trend
+    trend_coeff = zeros(nobs,1);
+    t = options_.trend_coeffs;
+    for i=1:length(t)
+        if ~isempty(t{i})
+            trend_coeff(i) = evalin('base',t{i});
+        end
+    end
+    trend = repmat(constant,1,gend)+trend_coeff*[1:gend];
+else
+    trend = repmat(constant,1,gend);
+end
+start = options_.presample+1;
+np    = size(T,1);
+mf    = bayestopt_.mf;
+no_missing_data_flag = (number_of_observations==gend*nobs);
+%------------------------------------------------------------------------------
+% 3. Initial condition of the Kalman filter
+%------------------------------------------------------------------------------
+T
+R
+Q
+R*Q*R'
+pause
+options_.lik_init = 1;
+kalman_algo = options_.kalman_algo;
+if options_.lik_init == 1               % Kalman filter
+    if kalman_algo ~= 2
+        kalman_algo = 1;
+    end
+    Pstar = lyapunov_symm(T,R*Q*R',options_.qz_criterium,options_.lyapunov_complex_threshold);
+    Pinf        = [];
+elseif options_.lik_init == 2   % Old Diffuse Kalman filter
+    if kalman_algo ~= 2
+        kalman_algo = 1;
+    end
+    Pstar = options_.Harvey_scale_factor*eye(np);
+    Pinf = [];
+elseif options_.lik_init == 3   % Diffuse Kalman filter
+    if kalman_algo ~= 4
+        kalman_algo = 3;
+    end
+    [QT,ST] = schur(T);
+    e1 = abs(ordeig(ST)) > 2-options_.qz_criterium;
+    [QT,ST] = ordschur(QT,ST,e1);
+    k = find(abs(ordeig(ST)) > 2-options_.qz_criterium);
+    nk = length(k);
+    nk1 = nk+1;
+    Pinf = zeros(np,np);
+    Pinf(1:nk,1:nk) = eye(nk);
+    Pstar = zeros(np,np);
+    B = QT'*R*Q*R'*QT;
+    for i=np:-1:nk+2
+        if ST(i,i-1) == 0
+            if i == np
+                c = zeros(np-nk,1);
+            else
+                c = ST(nk1:i,:)*(Pstar(:,i+1:end)*ST(i,i+1:end)')+...
+                    ST(i,i)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i);
+            end
+            q = eye(i-nk)-ST(nk1:i,nk1:i)*ST(i,i);
+            Pstar(nk1:i,i) = q\(B(nk1:i,i)+c);
+            Pstar(i,nk1:i-1) = Pstar(nk1:i-1,i)';
+        else
+            if i == np
+                c = zeros(np-nk,1);
+                c1 = zeros(np-nk,1);
+            else
+                c = ST(nk1:i,:)*(Pstar(:,i+1:end)*ST(i,i+1:end)')+...
+                    ST(i,i)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i)+...
+                    ST(i,i-1)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i-1);
+                c1 = ST(nk1:i,:)*(Pstar(:,i+1:end)*ST(i-1,i+1:end)')+...
+                     ST(i-1,i-1)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i-1)+...
+                     ST(i-1,i)*ST(nk1:i,i+1:end)*Pstar(i+1:end,i);
+            end
+            q = [eye(i-nk)-ST(nk1:i,nk1:i)*ST(i,i) -ST(nk1:i,nk1:i)*ST(i,i-1);...
+                 -ST(nk1:i,nk1:i)*ST(i-1,i) eye(i-nk)-ST(nk1:i,nk1:i)*ST(i-1,i-1)];
+            z =  q\[B(nk1:i,i)+c;B(nk1:i,i-1)+c1];
+            Pstar(nk1:i,i) = z(1:(i-nk));
+            Pstar(nk1:i,i-1) = z(i-nk+1:end);
+            Pstar(i,nk1:i-1) = Pstar(nk1:i-1,i)';
+            Pstar(i-1,nk1:i-2) = Pstar(nk1:i-2,i-1)';
+            i = i - 1;
+        end
+    end
+    if i == nk+2
+        c = ST(nk+1,:)*(Pstar(:,nk+2:end)*ST(nk1,nk+2:end)')+ST(nk1,nk1)*ST(nk1,nk+2:end)*Pstar(nk+2:end,nk1);
+        Pstar(nk1,nk1)=(B(nk1,nk1)+c)/(1-ST(nk1,nk1)*ST(nk1,nk1));
+    end
+    Z = QT(mf,:);
+    R1 = QT'*R;
+    [QQ,RR,EE] = qr(Z*ST(:,1:nk),0);
+    k = find(abs(diag([RR; zeros(nk-size(Z,1),size(RR,2))])) < 1e-8);
+    if length(k) > 0
+        k1 = EE(:,k);
+        dd =ones(nk,1);
+        dd(k1) = zeros(length(k1),1);
+        Pinf(1:nk,1:nk) = diag(dd);
+    end
+end
+if kalman_algo == 2
+end
+kalman_tol = options_.kalman_tol;
+riccati_tol = options_.riccati_tol;
+mf = bayestopt_.mf1;
+Y   = data-trend;
+Pstar
+pause
+%------------------------------------------------------------------------------
+% 4. Likelihood evaluation
+%------------------------------------------------------------------------------
+if (kalman_algo==1)% Multivariate Kalman Filter
+    if no_missing_data_flag
+        LIK = kalman_filter(T,R,Q,H,Pstar,Y,start,mf,kalman_tol,riccati_tol); 
+    else
+        LIK = ...
+            missing_observations_kalman_filter(T,R,Q,H,Pstar,Y,start,mf,kalman_tol,riccati_tol, ...
+                                               data_index,number_of_observations,no_more_missing_observations);
+    end
+    if isinf(LIK)
+        kalman_algo = 2;
+    end
+end
+if (kalman_algo==2)% Univariate Kalman Filter
+    no_correlation_flag = 1;
+    if length(H)==1 & H == 0
+        H = zeros(nobs,1);
+    else
+        if all(all(abs(H-diag(diag(H)))<1e-14))% ie, the covariance matrix is diagonal...
+            H = diag(H);
+        else
+            no_correlation_flag = 0;
+        end
+    end
+    if no_correlation_flag
+        LIK = univariate_kalman_filter(T,R,Q,H,Pstar,Y,start,mf,kalman_tol,riccati_tol,data_index,number_of_observations,no_more_missing_observations);
+    else
+        LIK = univariate_kalman_filter_corr(T,R,Q,H,Pstar,Y,start,mf,kalman_tol,riccati_tol,data_index,number_of_observations,no_more_missing_observations);
+    end
+end
+if (kalman_algo==3)% Multivariate Diffuse Kalman Filter
+    if no_missing_data_flag
+        LIK = diffuse_kalman_filter(ST,R1,Q,H,Pinf,Pstar,Y,start,Z,kalman_tol, ...
+                                    riccati_tol);
+    else
+        LIK = missing_observations_diffuse_kalman_filter(ST,R1,Q,H,Pinf, ...
+                                                         Pstar,Y,start,Z,kalman_tol,riccati_tol,...
+                                                         data_index,number_of_observations,...
+                                                         no_more_missing_observations);
+    end
+    if isinf(LIK)
+        kalman_algo = 4;
+    end
+end
+if (kalman_algo==4)% Univariate Diffuse Kalman Filter
+    no_correlation_flag = 1;
+    if length(H)==1 & H == 0
+        H = zeros(nobs,1);
+    else
+        if all(all(abs(H-diag(diag(H)))<1e-14))% ie, the covariance matrix is diagonal...
+            H = diag(H);
+        else
+            no_correlation_flag = 0;
+        end
+    end
+    if no_correlation_flag
+        LIK = univariate_diffuse_kalman_filter(ST,R1,Q,H,Pinf,Pstar,Y, ...
+                                               start,Z,kalman_tol,riccati_tol,data_index,...
+                                               number_of_observations,no_more_missing_observations);
+    else
+        LIK = univariate_diffuse_kalman_filter_corr(ST,R1,Q,H,Pinf,Pstar, ...
+                                                    Y,start,Z,kalman_tol,riccati_tol,...
+                                                    data_index,number_of_observations,...
+                                                    no_more_missing_observations);
+    end
+end
+if isnan(LIK)
+    cost_flag = 0;
+    return
+end
+if imag(LIK)~=0
+    likelihood = bayestopt_.penalty;
+else
+    likelihood = LIK;
+end
+% ------------------------------------------------------------------------------
+% Adds prior if necessary
+% ------------------------------------------------------------------------------
+lnprior = priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7,bayestopt_.p3,bayestopt_.p4);
+fval    = (likelihood-lnprior);
+likelihood
+lnprior
+fval
+pause
+LIKDLL=logposterior(xparam1,Y,mexext)
+pause
+options_.kalman_algo = kalman_algo;
diff --git a/mex/sources/estimation/tests/logposterior_dll_test/rawdata_euromodel_1.m b/mex/sources/estimation/tests/logposterior_dll_test/rawdata_euromodel_1.m
index cde44abc94..25bbc92414 100644
--- a/mex/sources/estimation/tests/logposterior_dll_test/rawdata_euromodel_1.m
+++ b/mex/sources/estimation/tests/logposterior_dll_test/rawdata_euromodel_1.m
@@ -1,967 +1,967 @@
-C =[
-   -7.4073
-   -6.1860
-   -6.5983
-   -5.6088
-   -5.0547
-   -4.4774
-   -3.8081
-   -3.8425
-   -2.4178
-   -1.9835
-   -1.0395
-   -0.1583
-   -0.0397
-    0.3505
-   -0.1879
-   -0.0067
-    0.0478
-   -1.2247
-   -1.4349
-   -0.7973
-   -0.0461
-    0.5844
-    1.1372
-    1.3801
-    1.8023
-    2.2972
-    2.0469
-    2.5435
-    2.8169
-    3.2007
-    2.6705
-    3.0518
-    3.2445
-    3.8443
-    3.8525
-    4.9494
-    4.2770
-    4.9532
-    5.1441
-    3.7124
-    3.9880
-    3.6926
-    2.6005
-    1.8679
-    1.9085
-    1.5563
-    1.2308
-    0.3264
-   -0.2208
-   -0.2483
-   -0.4082
-   -1.0315
-   -1.6030
-   -1.5499
-   -1.3777
-   -2.1675
-   -2.5138
-   -2.8820
-   -2.6958
-   -2.4719
-   -1.9854
-   -1.7954
-   -2.2362
-   -1.0595
-   -0.8808
-   -0.8548
-   -1.2839
-   -0.1363
-    0.2104
-    0.8810
-    0.3555
-    0.4766
-    1.3269
-    1.4506
-    1.4308
-    1.6263
-    1.9842
-    2.3948
-    2.8710
-    3.0177
-    2.9305
-    3.1739
-    3.7380
-    3.8285
-    3.3342
-    3.7447
-    3.7830
-    3.1039
-    2.8413
-    3.0338
-    0.3669
-    0.0847
-    0.0104
-    0.2115
-   -0.6649
-   -0.9625
-   -0.7330
-   -0.8664
-   -1.4441
-   -1.0179
-   -1.2729
-   -1.9539
-   -1.4427
-   -2.0371
-   -1.9764
-   -2.5654
-   -2.8570
-   -2.5842
-   -3.0427
-   -2.8312
-   -2.3320
-   -2.2768
-   -2.1816
-   -2.1043
-   -1.8969
-   -2.2388
-   -2.1679
-   -2.1172
-];
-
-E =[
-    0.6263
-    0.7368
-    0.7477
-    1.0150
-    0.6934
-    0.4135
-    0.3845
-    0.2380
-    0.2853
-    0.5999
-    0.8622
-    1.2116
-    1.4921
-    1.5816
-    1.7259
-    1.6276
-    1.2422
-    0.8084
-    0.4710
-   -0.3704
-   -0.6427
-   -0.5323
-   -0.5562
-   -0.3651
-   -0.4356
-   -0.7164
-   -0.5816
-   -0.4635
-   -0.8456
-   -0.9708
-   -0.7138
-   -0.7499
-   -0.6941
-   -0.6656
-   -0.2912
-   -0.1650
-    0.0774
-    0.2307
-    0.4484
-    0.4942
-    0.4653
-    0.2196
-    0.1736
-   -0.1595
-   -0.3918
-   -0.4611
-   -0.8493
-   -0.7384
-   -1.0604
-   -1.2166
-   -1.7187
-   -1.6932
-   -1.7830
-   -1.7035
-   -2.2079
-   -2.3769
-   -2.2511
-   -2.1093
-   -2.4638
-   -2.4027
-   -2.1313
-   -1.9199
-   -1.7941
-   -1.4661
-   -1.2269
-   -1.0392
-   -1.0725
-   -0.7156
-   -0.4778
-   -0.4233
-   -0.0409
-    0.1620
-    0.4280
-    0.5873
-    1.0323
-    1.3420
-    1.6902
-    2.0680
-    2.8219
-    3.2511
-    3.2930
-    3.5633
-    3.8992
-    3.6874
-    3.2849
-    3.1614
-    2.6221
-    2.5067
-    1.9223
-    1.1777
-    0.4483
-   -0.0661
-   -0.4424
-   -0.9000
-   -1.1478
-   -1.2047
-   -1.1412
-   -1.2383
-   -1.1048
-   -0.9716
-   -0.9287
-   -1.0057
-   -1.0827
-   -1.0200
-   -1.0072
-   -1.1740
-   -1.2809
-   -1.1086
-   -0.9866
-   -0.8947
-   -0.5875
-   -0.2329
-    0.1493
-    0.4906
-    0.8400
-    1.0720
-    1.2648
-    1.5431
-];
-
-I =[
-    2.6617
-    2.4325
-    1.9592
-    3.2530
-    2.9949
-    3.7918
-    4.7444
-    4.8289
-    5.5983
-    7.8923
-    9.4297
-    9.5010
-   10.0150
-   10.0413
-    9.6046
-    6.4766
-    5.9647
-    3.0114
-    0.5683
-   -2.1226
-   -2.1855
-   -0.8329
-   -1.5207
-   -1.3419
-   -1.7897
-   -0.1476
-    0.4675
-   -1.6516
-   -1.5419
-   -1.3050
-   -1.2451
-   -0.7815
-   -0.7796
-   -0.3612
-   -2.4072
-    1.1162
-    1.1383
-    3.4132
-    5.0356
-    2.8016
-    2.1734
-    0.9366
-   -0.7050
-   -1.5021
-   -2.9868
-   -6.0237
-   -6.2589
-   -6.9138
-   -8.2340
-   -9.2589
-   -9.2465
-   -9.6988
-   -9.7782
-  -10.5645
-  -10.7544
-  -13.1583
-  -12.2718
-  -12.0131
-  -13.5983
-  -12.3579
-  -10.9146
-  -11.1572
-  -12.4935
-   -9.4393
-   -8.5535
-   -7.3723
-  -10.0169
-   -6.6088
-   -5.2045
-   -4.1024
-   -2.8472
-   -1.3139
-    0.0477
-    1.5629
-    3.6947
-    4.0327
-    4.1320
-    7.1400
-    9.1036
-    8.5609
-    7.6576
-    8.8022
-    8.9611
-   10.0871
-    9.4797
-    9.3964
-   10.0363
-    8.6340
-    6.6522
-    4.4471
-    0.2854
-   -2.1879
-   -2.9879
-   -4.1021
-   -2.7713
-   -2.2281
-   -1.2908
-   -0.3250
-    0.6534
-    0.3942
-    0.3534
-   -0.1532
-   -1.7936
-    0.4909
-    0.3634
-    0.4290
-   -0.9709
-    0.1942
-    0.6103
-    1.4426
-    2.7225
-    1.7525
-    3.2780
-    3.5985
-    4.9011
-    5.3312
-    6.4402
-    6.6529
-];
-
-L =[
-    0.6263
-    0.7368
-    0.7477
-    1.0150
-    0.6934
-    0.4135
-    0.3845
-    0.2380
-    0.2853
-    0.5999
-    0.8622
-    1.2116
-    1.4921
-    1.5816
-    1.7259
-    1.6276
-    1.2422
-    0.8084
-    0.4710
-   -0.3704
-   -0.6427
-   -0.5323
-   -0.5562
-   -0.3651
-   -0.4356
-   -0.7164
-   -0.5816
-   -0.4635
-   -0.8456
-   -0.9708
-   -0.7138
-   -0.7499
-   -0.6941
-   -0.6656
-   -0.2912
-   -0.1650
-    0.0774
-    0.2307
-    0.4484
-    0.4942
-    0.4653
-    0.2196
-    0.1736
-   -0.1595
-   -0.3918
-   -0.4611
-   -0.8493
-   -0.7384
-   -1.0604
-   -1.2166
-   -1.7187
-   -1.6932
-   -1.7830
-   -1.7035
-   -2.2079
-   -2.3769
-   -2.2511
-   -2.1093
-   -2.4638
-   -2.4027
-   -2.1313
-   -1.9199
-   -1.7941
-   -1.4661
-   -1.2269
-   -1.0392
-   -1.0725
-   -0.7156
-   -0.4778
-   -0.4233
-   -0.0409
-    0.1620
-    0.4280
-    0.5873
-    1.0323
-    1.3420
-    1.6902
-    2.0680
-    2.8219
-    3.2511
-    3.2930
-    3.5633
-    3.8992
-    3.6874
-    3.2849
-    3.1614
-    2.6221
-    2.5067
-    1.9223
-    1.1777
-    0.4483
-   -0.0661
-   -0.4424
-   -0.9000
-   -1.1478
-   -1.2047
-   -1.1412
-   -1.2383
-   -1.1048
-   -0.9716
-   -0.9287
-   -1.0057
-   -1.0827
-   -1.0200
-   -1.0072
-   -1.1740
-   -1.2809
-   -1.1086
-   -0.9866
-   -0.8947
-   -0.5875
-   -0.2329
-    0.1493
-    0.4906
-    0.8400
-    1.0720
-    1.2648
-    1.5431
-];
-
-PIE =[
-   -1.0113
-   -0.8305
-    0.2332
-   -0.8746
-   -0.7978
-   -0.9220
-   -0.2487
-   -0.7749
-   -0.5460
-   -0.5347
-    0.5050
-   -0.0334
-    0.6756
-    0.8791
-    0.7267
-    1.0997
-    1.1750
-    1.1927
-    0.4420
-    0.5357
-    0.0345
-    0.0196
-    0.3371
-    0.9379
-    1.2160
-    0.3393
-    0.5813
-    0.7410
-    0.3374
-    0.2616
-    0.4025
-    0.4799
-    0.5981
-   -0.1523
-    0.4458
-    0.2182
-    0.9793
-    0.7562
-    1.0064
-    0.8203
-    0.6966
-    0.3352
-    0.6581
-    0.6111
-    0.9833
-    1.1991
-    0.9562
-    0.3868
-    0.2939
-    0.2471
-    0.8331
-    0.0715
-    0.3910
-    0.3301
-    0.2547
-   -0.2702
-   -0.2998
-   -0.1953
-   -0.2293
-   -0.3284
-    0.0480
-   -0.0374
-    0.3253
-   -0.3434
-   -0.3892
-   -0.7178
-   -0.4758
-   -0.6794
-   -0.8505
-   -0.3512
-   -0.4436
-   -0.5101
-   -0.4574
-   -0.2696
-   -0.1047
-   -0.5745
-   -0.2989
-   -0.0063
-    0.0088
-   -0.1184
-   -0.1506
-   -0.4073
-    0.2674
-    0.2896
-    0.0669
-    0.1166
-   -0.1699
-   -0.2518
-   -0.0562
-   -0.3269
-   -0.0703
-   -0.1046
-   -0.4888
-   -0.3524
-   -0.2485
-   -0.5870
-   -0.4546
-   -0.3970
-   -0.2353
-   -0.0352
-   -0.2171
-   -0.3754
-   -0.4322
-   -0.4572
-   -0.4903
-   -0.4518
-   -0.6435
-   -0.6304
-   -0.4148
-   -0.2892
-   -0.4318
-   -0.6010
-   -0.4148
-   -0.4315
-   -0.3531
-   -0.8053
-   -0.4680
-   -0.4263
-];
-
-R =[
-   -1.0750
-   -1.1540
-   -1.3682
-   -1.4569
-   -1.3490
-   -1.4011
-   -1.6486
-   -1.6968
-   -1.6976
-   -1.2567
-   -1.1392
-   -0.7783
-   -0.3021
-   -0.0435
-    0.0066
-   -0.0043
-    0.1029
-   -0.0628
-   -0.5358
-   -0.9627
-   -1.1079
-   -1.0918
-   -0.9966
-   -0.6223
-   -0.3616
-   -0.2711
-   -0.0997
-   -0.2810
-   -0.3710
-   -0.3167
-   -0.5301
-   -0.5826
-   -0.3194
-   -0.2713
-   -0.5287
-   -0.2432
-    0.1098
-    0.5349
-    0.7094
-    0.8415
-    0.6226
-    0.7376
-    0.9316
-    1.4370
-    1.5853
-    1.4267
-    1.1783
-    1.2046
-    0.9689
-    0.7918
-    0.6315
-    0.5950
-    0.6853
-    0.7171
-    0.5887
-    0.4873
-    0.4027
-    0.3489
-    0.2934
-    0.3060
-    0.1741
-    0.0348
-    0.0771
-   -0.1005
-   -0.1518
-   -0.1104
-   -0.0681
-   -0.0059
-    0.0256
-    0.0404
-   -0.1721
-   -0.2002
-    0.0015
-    0.1249
-    0.3738
-    0.4320
-    0.5579
-    0.8186
-    0.8727
-    0.7356
-    0.7243
-    0.8635
-    0.9058
-    0.7656
-    0.7936
-    0.8631
-    0.9074
-    0.9547
-    1.2045
-    1.0850
-    0.9178
-    0.5242
-    0.3178
-    0.1472
-    0.0227
-   -0.0799
-   -0.0611
-   -0.0140
-    0.1132
-    0.1774
-    0.0782
-    0.0436
-   -0.1596
-   -0.2691
-   -0.2895
-   -0.3791
-   -0.4020
-   -0.4166
-   -0.4037
-   -0.3636
-   -0.4075
-   -0.4311
-   -0.4470
-   -0.5111
-   -0.6274
-   -0.7261
-   -0.6974
-   -0.5012
-];
-
-W =[
-  -14.8791
-  -13.2300
-  -13.5037
-  -13.0249
-  -11.2546
-  -10.0148
-   -8.8586
-   -8.5739
-   -7.7851
-   -6.7136
-   -5.5878
-   -4.6881
-   -3.8039
-   -3.0366
-   -2.7342
-   -1.3135
-   -0.7387
-   -0.1131
-   -0.2769
-    0.8696
-    1.8855
-    2.3667
-    2.4942
-    3.2049
-    3.9682
-    5.1500
-    4.7047
-    4.7827
-    5.3377
-    5.6614
-    5.2813
-    5.2967
-    5.5175
-    6.1526
-    5.6627
-    6.0694
-    6.5824
-    6.9032
-    6.7849
-    6.6896
-    6.6201
-    6.9933
-    5.8959
-    6.7419
-    6.9999
-    6.4009
-    5.5083
-    5.1054
-    5.2813
-    4.5790
-    3.9589
-    3.8599
-    3.8978
-    2.7957
-    3.2480
-    1.4634
-    1.9219
-    1.8398
-    1.9279
-    1.8316
-    1.6092
-    1.2741
-    0.2031
-   -0.0236
-   -0.1004
-   -0.3034
-   -1.0273
-   -0.2205
-    0.0458
-    0.2386
-   -0.0977
-   -0.3145
-   -0.1416
-   -0.7009
-   -0.9082
-   -0.8802
-   -0.5644
-   -0.5852
-   -0.5346
-    0.0652
-    0.1301
-    0.3444
-   -0.3592
-    0.8096
-    0.9644
-    1.0289
-    1.2781
-    1.2298
-    2.2134
-    2.0808
-    0.4925
-    0.6506
-    0.5531
-    0.2456
-   -0.5351
-   -0.8183
-   -0.8967
-   -0.7268
-   -1.0738
-   -1.2844
-   -1.4338
-   -1.6995
-   -1.7085
-   -2.2889
-   -2.1018
-   -2.4273
-   -2.4609
-   -2.1407
-   -2.3847
-   -3.1689
-   -4.5581
-   -4.1027
-   -4.2436
-   -4.8836
-   -5.9660
-   -4.9971
-   -5.2386
-   -5.6618
-];
-
-Y =[
-   -4.9347
-   -4.6205
-   -5.2198
-   -4.5937
-   -3.8015
-   -3.6643
-   -2.7239
-   -2.7524
-   -2.0634
-   -1.0112
-    0.0530
-    0.7623
-    1.7927
-    2.1486
-    2.4866
-    2.1456
-    2.1671
-   -0.0254
-   -1.6716
-   -1.9673
-   -1.6109
-   -1.0292
-   -0.1222
-    0.7329
-    1.1234
-    2.0603
-    1.7998
-    1.4820
-    1.1732
-    1.6424
-    1.5382
-    2.1399
-    2.0127
-    2.7210
-    2.4966
-    3.5249
-    3.6237
-    4.2011
-    4.5634
-    3.3442
-    2.7761
-    1.9812
-    1.3779
-    1.4616
-    1.3029
-    0.7594
-    0.3695
-    0.0832
-   -0.8118
-   -1.4557
-   -1.4850
-   -1.2346
-   -1.5696
-   -1.3785
-   -0.7682
-   -2.0308
-   -1.7778
-   -1.7801
-   -2.1711
-   -1.7469
-   -1.3413
-   -1.3352
-   -2.4390
-   -1.2125
-   -1.1695
-   -1.0891
-   -2.4753
-   -1.3503
-   -0.9412
-   -0.1470
-    0.0026
-    0.1108
-    0.6890
-    1.3520
-    1.6018
-    2.0667
-    1.7625
-    2.6658
-    3.4048
-    3.2507
-    3.4251
-    3.2174
-    3.1903
-    3.3396
-    3.1358
-    2.8625
-    3.3546
-    2.4609
-    1.9534
-    0.9962
-   -0.7904
-   -1.1672
-   -1.2586
-   -1.3593
-   -1.3443
-   -0.9413
-   -0.6023
-   -0.4516
-   -0.5129
-   -0.8741
-   -1.0784
-   -1.4091
-   -1.3627
-   -1.5731
-   -1.6037
-   -1.8814
-   -2.1482
-   -1.3597
-   -1.1855
-   -1.1122
-   -0.8424
-   -0.9747
-   -1.1385
-   -1.4548
-   -1.4284
-   -1.4633
-   -1.0621
-   -0.7871
-];
+C =[
+   -7.4073
+   -6.1860
+   -6.5983
+   -5.6088
+   -5.0547
+   -4.4774
+   -3.8081
+   -3.8425
+   -2.4178
+   -1.9835
+   -1.0395
+   -0.1583
+   -0.0397
+    0.3505
+   -0.1879
+   -0.0067
+    0.0478
+   -1.2247
+   -1.4349
+   -0.7973
+   -0.0461
+    0.5844
+    1.1372
+    1.3801
+    1.8023
+    2.2972
+    2.0469
+    2.5435
+    2.8169
+    3.2007
+    2.6705
+    3.0518
+    3.2445
+    3.8443
+    3.8525
+    4.9494
+    4.2770
+    4.9532
+    5.1441
+    3.7124
+    3.9880
+    3.6926
+    2.6005
+    1.8679
+    1.9085
+    1.5563
+    1.2308
+    0.3264
+   -0.2208
+   -0.2483
+   -0.4082
+   -1.0315
+   -1.6030
+   -1.5499
+   -1.3777
+   -2.1675
+   -2.5138
+   -2.8820
+   -2.6958
+   -2.4719
+   -1.9854
+   -1.7954
+   -2.2362
+   -1.0595
+   -0.8808
+   -0.8548
+   -1.2839
+   -0.1363
+    0.2104
+    0.8810
+    0.3555
+    0.4766
+    1.3269
+    1.4506
+    1.4308
+    1.6263
+    1.9842
+    2.3948
+    2.8710
+    3.0177
+    2.9305
+    3.1739
+    3.7380
+    3.8285
+    3.3342
+    3.7447
+    3.7830
+    3.1039
+    2.8413
+    3.0338
+    0.3669
+    0.0847
+    0.0104
+    0.2115
+   -0.6649
+   -0.9625
+   -0.7330
+   -0.8664
+   -1.4441
+   -1.0179
+   -1.2729
+   -1.9539
+   -1.4427
+   -2.0371
+   -1.9764
+   -2.5654
+   -2.8570
+   -2.5842
+   -3.0427
+   -2.8312
+   -2.3320
+   -2.2768
+   -2.1816
+   -2.1043
+   -1.8969
+   -2.2388
+   -2.1679
+   -2.1172
+];
+
+E =[
+    0.6263
+    0.7368
+    0.7477
+    1.0150
+    0.6934
+    0.4135
+    0.3845
+    0.2380
+    0.2853
+    0.5999
+    0.8622
+    1.2116
+    1.4921
+    1.5816
+    1.7259
+    1.6276
+    1.2422
+    0.8084
+    0.4710
+   -0.3704
+   -0.6427
+   -0.5323
+   -0.5562
+   -0.3651
+   -0.4356
+   -0.7164
+   -0.5816
+   -0.4635
+   -0.8456
+   -0.9708
+   -0.7138
+   -0.7499
+   -0.6941
+   -0.6656
+   -0.2912
+   -0.1650
+    0.0774
+    0.2307
+    0.4484
+    0.4942
+    0.4653
+    0.2196
+    0.1736
+   -0.1595
+   -0.3918
+   -0.4611
+   -0.8493
+   -0.7384
+   -1.0604
+   -1.2166
+   -1.7187
+   -1.6932
+   -1.7830
+   -1.7035
+   -2.2079
+   -2.3769
+   -2.2511
+   -2.1093
+   -2.4638
+   -2.4027
+   -2.1313
+   -1.9199
+   -1.7941
+   -1.4661
+   -1.2269
+   -1.0392
+   -1.0725
+   -0.7156
+   -0.4778
+   -0.4233
+   -0.0409
+    0.1620
+    0.4280
+    0.5873
+    1.0323
+    1.3420
+    1.6902
+    2.0680
+    2.8219
+    3.2511
+    3.2930
+    3.5633
+    3.8992
+    3.6874
+    3.2849
+    3.1614
+    2.6221
+    2.5067
+    1.9223
+    1.1777
+    0.4483
+   -0.0661
+   -0.4424
+   -0.9000
+   -1.1478
+   -1.2047
+   -1.1412
+   -1.2383
+   -1.1048
+   -0.9716
+   -0.9287
+   -1.0057
+   -1.0827
+   -1.0200
+   -1.0072
+   -1.1740
+   -1.2809
+   -1.1086
+   -0.9866
+   -0.8947
+   -0.5875
+   -0.2329
+    0.1493
+    0.4906
+    0.8400
+    1.0720
+    1.2648
+    1.5431
+];
+
+I =[
+    2.6617
+    2.4325
+    1.9592
+    3.2530
+    2.9949
+    3.7918
+    4.7444
+    4.8289
+    5.5983
+    7.8923
+    9.4297
+    9.5010
+   10.0150
+   10.0413
+    9.6046
+    6.4766
+    5.9647
+    3.0114
+    0.5683
+   -2.1226
+   -2.1855
+   -0.8329
+   -1.5207
+   -1.3419
+   -1.7897
+   -0.1476
+    0.4675
+   -1.6516
+   -1.5419
+   -1.3050
+   -1.2451
+   -0.7815
+   -0.7796
+   -0.3612
+   -2.4072
+    1.1162
+    1.1383
+    3.4132
+    5.0356
+    2.8016
+    2.1734
+    0.9366
+   -0.7050
+   -1.5021
+   -2.9868
+   -6.0237
+   -6.2589
+   -6.9138
+   -8.2340
+   -9.2589
+   -9.2465
+   -9.6988
+   -9.7782
+  -10.5645
+  -10.7544
+  -13.1583
+  -12.2718
+  -12.0131
+  -13.5983
+  -12.3579
+  -10.9146
+  -11.1572
+  -12.4935
+   -9.4393
+   -8.5535
+   -7.3723
+  -10.0169
+   -6.6088
+   -5.2045
+   -4.1024
+   -2.8472
+   -1.3139
+    0.0477
+    1.5629
+    3.6947
+    4.0327
+    4.1320
+    7.1400
+    9.1036
+    8.5609
+    7.6576
+    8.8022
+    8.9611
+   10.0871
+    9.4797
+    9.3964
+   10.0363
+    8.6340
+    6.6522
+    4.4471
+    0.2854
+   -2.1879
+   -2.9879
+   -4.1021
+   -2.7713
+   -2.2281
+   -1.2908
+   -0.3250
+    0.6534
+    0.3942
+    0.3534
+   -0.1532
+   -1.7936
+    0.4909
+    0.3634
+    0.4290
+   -0.9709
+    0.1942
+    0.6103
+    1.4426
+    2.7225
+    1.7525
+    3.2780
+    3.5985
+    4.9011
+    5.3312
+    6.4402
+    6.6529
+];
+
+L =[
+    0.6263
+    0.7368
+    0.7477
+    1.0150
+    0.6934
+    0.4135
+    0.3845
+    0.2380
+    0.2853
+    0.5999
+    0.8622
+    1.2116
+    1.4921
+    1.5816
+    1.7259
+    1.6276
+    1.2422
+    0.8084
+    0.4710
+   -0.3704
+   -0.6427
+   -0.5323
+   -0.5562
+   -0.3651
+   -0.4356
+   -0.7164
+   -0.5816
+   -0.4635
+   -0.8456
+   -0.9708
+   -0.7138
+   -0.7499
+   -0.6941
+   -0.6656
+   -0.2912
+   -0.1650
+    0.0774
+    0.2307
+    0.4484
+    0.4942
+    0.4653
+    0.2196
+    0.1736
+   -0.1595
+   -0.3918
+   -0.4611
+   -0.8493
+   -0.7384
+   -1.0604
+   -1.2166
+   -1.7187
+   -1.6932
+   -1.7830
+   -1.7035
+   -2.2079
+   -2.3769
+   -2.2511
+   -2.1093
+   -2.4638
+   -2.4027
+   -2.1313
+   -1.9199
+   -1.7941
+   -1.4661
+   -1.2269
+   -1.0392
+   -1.0725
+   -0.7156
+   -0.4778
+   -0.4233
+   -0.0409
+    0.1620
+    0.4280
+    0.5873
+    1.0323
+    1.3420
+    1.6902
+    2.0680
+    2.8219
+    3.2511
+    3.2930
+    3.5633
+    3.8992
+    3.6874
+    3.2849
+    3.1614
+    2.6221
+    2.5067
+    1.9223
+    1.1777
+    0.4483
+   -0.0661
+   -0.4424
+   -0.9000
+   -1.1478
+   -1.2047
+   -1.1412
+   -1.2383
+   -1.1048
+   -0.9716
+   -0.9287
+   -1.0057
+   -1.0827
+   -1.0200
+   -1.0072
+   -1.1740
+   -1.2809
+   -1.1086
+   -0.9866
+   -0.8947
+   -0.5875
+   -0.2329
+    0.1493
+    0.4906
+    0.8400
+    1.0720
+    1.2648
+    1.5431
+];
+
+PIE =[
+   -1.0113
+   -0.8305
+    0.2332
+   -0.8746
+   -0.7978
+   -0.9220
+   -0.2487
+   -0.7749
+   -0.5460
+   -0.5347
+    0.5050
+   -0.0334
+    0.6756
+    0.8791
+    0.7267
+    1.0997
+    1.1750
+    1.1927
+    0.4420
+    0.5357
+    0.0345
+    0.0196
+    0.3371
+    0.9379
+    1.2160
+    0.3393
+    0.5813
+    0.7410
+    0.3374
+    0.2616
+    0.4025
+    0.4799
+    0.5981
+   -0.1523
+    0.4458
+    0.2182
+    0.9793
+    0.7562
+    1.0064
+    0.8203
+    0.6966
+    0.3352
+    0.6581
+    0.6111
+    0.9833
+    1.1991
+    0.9562
+    0.3868
+    0.2939
+    0.2471
+    0.8331
+    0.0715
+    0.3910
+    0.3301
+    0.2547
+   -0.2702
+   -0.2998
+   -0.1953
+   -0.2293
+   -0.3284
+    0.0480
+   -0.0374
+    0.3253
+   -0.3434
+   -0.3892
+   -0.7178
+   -0.4758
+   -0.6794
+   -0.8505
+   -0.3512
+   -0.4436
+   -0.5101
+   -0.4574
+   -0.2696
+   -0.1047
+   -0.5745
+   -0.2989
+   -0.0063
+    0.0088
+   -0.1184
+   -0.1506
+   -0.4073
+    0.2674
+    0.2896
+    0.0669
+    0.1166
+   -0.1699
+   -0.2518
+   -0.0562
+   -0.3269
+   -0.0703
+   -0.1046
+   -0.4888
+   -0.3524
+   -0.2485
+   -0.5870
+   -0.4546
+   -0.3970
+   -0.2353
+   -0.0352
+   -0.2171
+   -0.3754
+   -0.4322
+   -0.4572
+   -0.4903
+   -0.4518
+   -0.6435
+   -0.6304
+   -0.4148
+   -0.2892
+   -0.4318
+   -0.6010
+   -0.4148
+   -0.4315
+   -0.3531
+   -0.8053
+   -0.4680
+   -0.4263
+];
+
+R =[
+   -1.0750
+   -1.1540
+   -1.3682
+   -1.4569
+   -1.3490
+   -1.4011
+   -1.6486
+   -1.6968
+   -1.6976
+   -1.2567
+   -1.1392
+   -0.7783
+   -0.3021
+   -0.0435
+    0.0066
+   -0.0043
+    0.1029
+   -0.0628
+   -0.5358
+   -0.9627
+   -1.1079
+   -1.0918
+   -0.9966
+   -0.6223
+   -0.3616
+   -0.2711
+   -0.0997
+   -0.2810
+   -0.3710
+   -0.3167
+   -0.5301
+   -0.5826
+   -0.3194
+   -0.2713
+   -0.5287
+   -0.2432
+    0.1098
+    0.5349
+    0.7094
+    0.8415
+    0.6226
+    0.7376
+    0.9316
+    1.4370
+    1.5853
+    1.4267
+    1.1783
+    1.2046
+    0.9689
+    0.7918
+    0.6315
+    0.5950
+    0.6853
+    0.7171
+    0.5887
+    0.4873
+    0.4027
+    0.3489
+    0.2934
+    0.3060
+    0.1741
+    0.0348
+    0.0771
+   -0.1005
+   -0.1518
+   -0.1104
+   -0.0681
+   -0.0059
+    0.0256
+    0.0404
+   -0.1721
+   -0.2002
+    0.0015
+    0.1249
+    0.3738
+    0.4320
+    0.5579
+    0.8186
+    0.8727
+    0.7356
+    0.7243
+    0.8635
+    0.9058
+    0.7656
+    0.7936
+    0.8631
+    0.9074
+    0.9547
+    1.2045
+    1.0850
+    0.9178
+    0.5242
+    0.3178
+    0.1472
+    0.0227
+   -0.0799
+   -0.0611
+   -0.0140
+    0.1132
+    0.1774
+    0.0782
+    0.0436
+   -0.1596
+   -0.2691
+   -0.2895
+   -0.3791
+   -0.4020
+   -0.4166
+   -0.4037
+   -0.3636
+   -0.4075
+   -0.4311
+   -0.4470
+   -0.5111
+   -0.6274
+   -0.7261
+   -0.6974
+   -0.5012
+];
+
+W =[
+  -14.8791
+  -13.2300
+  -13.5037
+  -13.0249
+  -11.2546
+  -10.0148
+   -8.8586
+   -8.5739
+   -7.7851
+   -6.7136
+   -5.5878
+   -4.6881
+   -3.8039
+   -3.0366
+   -2.7342
+   -1.3135
+   -0.7387
+   -0.1131
+   -0.2769
+    0.8696
+    1.8855
+    2.3667
+    2.4942
+    3.2049
+    3.9682
+    5.1500
+    4.7047
+    4.7827
+    5.3377
+    5.6614
+    5.2813
+    5.2967
+    5.5175
+    6.1526
+    5.6627
+    6.0694
+    6.5824
+    6.9032
+    6.7849
+    6.6896
+    6.6201
+    6.9933
+    5.8959
+    6.7419
+    6.9999
+    6.4009
+    5.5083
+    5.1054
+    5.2813
+    4.5790
+    3.9589
+    3.8599
+    3.8978
+    2.7957
+    3.2480
+    1.4634
+    1.9219
+    1.8398
+    1.9279
+    1.8316
+    1.6092
+    1.2741
+    0.2031
+   -0.0236
+   -0.1004
+   -0.3034
+   -1.0273
+   -0.2205
+    0.0458
+    0.2386
+   -0.0977
+   -0.3145
+   -0.1416
+   -0.7009
+   -0.9082
+   -0.8802
+   -0.5644
+   -0.5852
+   -0.5346
+    0.0652
+    0.1301
+    0.3444
+   -0.3592
+    0.8096
+    0.9644
+    1.0289
+    1.2781
+    1.2298
+    2.2134
+    2.0808
+    0.4925
+    0.6506
+    0.5531
+    0.2456
+   -0.5351
+   -0.8183
+   -0.8967
+   -0.7268
+   -1.0738
+   -1.2844
+   -1.4338
+   -1.6995
+   -1.7085
+   -2.2889
+   -2.1018
+   -2.4273
+   -2.4609
+   -2.1407
+   -2.3847
+   -3.1689
+   -4.5581
+   -4.1027
+   -4.2436
+   -4.8836
+   -5.9660
+   -4.9971
+   -5.2386
+   -5.6618
+];
+
+Y =[
+   -4.9347
+   -4.6205
+   -5.2198
+   -4.5937
+   -3.8015
+   -3.6643
+   -2.7239
+   -2.7524
+   -2.0634
+   -1.0112
+    0.0530
+    0.7623
+    1.7927
+    2.1486
+    2.4866
+    2.1456
+    2.1671
+   -0.0254
+   -1.6716
+   -1.9673
+   -1.6109
+   -1.0292
+   -0.1222
+    0.7329
+    1.1234
+    2.0603
+    1.7998
+    1.4820
+    1.1732
+    1.6424
+    1.5382
+    2.1399
+    2.0127
+    2.7210
+    2.4966
+    3.5249
+    3.6237
+    4.2011
+    4.5634
+    3.3442
+    2.7761
+    1.9812
+    1.3779
+    1.4616
+    1.3029
+    0.7594
+    0.3695
+    0.0832
+   -0.8118
+   -1.4557
+   -1.4850
+   -1.2346
+   -1.5696
+   -1.3785
+   -0.7682
+   -2.0308
+   -1.7778
+   -1.7801
+   -2.1711
+   -1.7469
+   -1.3413
+   -1.3352
+   -2.4390
+   -1.2125
+   -1.1695
+   -1.0891
+   -2.4753
+   -1.3503
+   -0.9412
+   -0.1470
+    0.0026
+    0.1108
+    0.6890
+    1.3520
+    1.6018
+    2.0667
+    1.7625
+    2.6658
+    3.4048
+    3.2507
+    3.4251
+    3.2174
+    3.1903
+    3.3396
+    3.1358
+    2.8625
+    3.3546
+    2.4609
+    1.9534
+    0.9962
+   -0.7904
+   -1.1672
+   -1.2586
+   -1.3593
+   -1.3443
+   -0.9413
+   -0.6023
+   -0.4516
+   -0.5129
+   -0.8741
+   -1.0784
+   -1.4091
+   -1.3627
+   -1.5731
+   -1.6037
+   -1.8814
+   -2.1482
+   -1.3597
+   -1.1855
+   -1.1122
+   -0.8424
+   -0.9747
+   -1.1385
+   -1.4548
+   -1.4284
+   -1.4633
+   -1.0621
+   -0.7871
+];
diff --git a/mex/sources/estimation/tests/logposterior_dll_test/sweuromodel_dll.mod b/mex/sources/estimation/tests/logposterior_dll_test/sweuromodel_dll.mod
index 999485ee82..a6a19f55b1 100644
--- a/mex/sources/estimation/tests/logposterior_dll_test/sweuromodel_dll.mod
+++ b/mex/sources/estimation/tests/logposterior_dll_test/sweuromodel_dll.mod
@@ -1,184 +1,184 @@
-//options_.usePartInfo=1;
-
-var MC E EF R_KF QF CF IF YF LF PIEF WF RF R_K Q C I Y L PIE W R EE_A PIE_BAR EE_B EE_G EE_L EE_I KF K one BIGTHETA;    
-
-varexo E_A E_B E_G E_L E_I ETA_R E_PIE_BAR ETA_Q ETA_P ETA_W  ;  
- 
-parameters 
-xi_e lambda_w alpha czcap beta phi_i tau sig_c hab ccs cinvs phi_y gamma_w xi_w gamma_p xi_p sig_l r_dpi 
-r_pie r_dy r_y rho rho_a rho_pb rho_b rho_g rho_l rho_i LMP  ;
-
-
-
-alpha=.30;
-beta=.99;
-tau=0.025;
-ccs=0.6;
-cinvs=.22;  //% alpha*(tau+ctrend)/R_K   R_K=ctrend/beta-1+tau  
-lambda_w = 0.5;
-phi_i= 6.771;
-sig_c=   1.353; 
-hab=    0.573;    
-xi_w=   0.737;
-sig_l=    2.400;
-xi_p=   0.908;
-xi_e= 0.599;
-gamma_w=    0.763;
-gamma_p=    0.469;
-czcap=    0.169;
-phi_y=    1.408;
-r_pie=     1.684;
-r_dpi=    0.14;
-rho=      0.961;
-r_y=      0.099;
-r_dy=     0.159;
-rho_a=    0.823;
-rho_b=    0.855;
-rho_g=    0.949;
-rho_l=   0.889;
-rho_i=   0.927;
-rho_pb=  0.924;
-LMP = 0.0 ; //NEW.
-
-model(linear, use_dll); 
-          CF = (1/(1+hab))*(CF(1)+hab*CF(-1))-((1-hab)/((1+hab)*sig_c))*(RF-PIEF(1)-EE_B) ;
-	      0 =  alpha*R_KF+(1-alpha)*WF -EE_A ;
-          PIEF = 0*one;
-	      IF = (1/(1+beta))* ((  IF(-1) + beta*(IF(1)))+(1/phi_i)*QF)+0*ETA_Q+EE_I ;
-	      QF = -(RF-PIEF(1))+(1-beta*(1-tau))*((0+czcap)/czcap)*R_KF(1)+beta*(1-tau)*QF(1) +0*EE_I ;
-          KF =  (1-tau)*KF(-1)+tau*IF(-1) ;
-	      YF = (ccs*CF+cinvs*IF)+EE_G  ;
-
-	      YF = 1*phi_y*( alpha*KF+alpha*(1/czcap)*R_KF+(1-alpha)*LF+EE_A ) ;
-	      WF = (sig_c/(1-hab))*(CF-hab*CF(-1)) + sig_l*LF - EE_L ;
-	      LF = R_KF*((1+czcap)/czcap)-WF+KF ;
-          EF = EF(-1)+EF(1)-EF+(LF-EF)*((1-xi_e)*(1-xi_e*beta)/(xi_e));
-         
-	      C = (hab/(1+hab))*C(-1)+(1/(1+hab))*C(1)-((1-hab)/((1+hab)*sig_c))*(R-PIE(1)-EE_B) ;
-	      I = (1/(1+beta))* ((  I(-1) + beta*(I(1)))+(1/phi_i)*Q )+1*ETA_Q+1*EE_I ;
-	      Q = -(R-PIE(1))+(1-beta*(1-tau))*((0+czcap)/czcap)*R_K(1)+beta*(1-tau)*Q(1) +EE_I*0+0*ETA_Q ;
-	      K =  (1-tau)*K(-1)+tau*I(-1) ;
-	      Y = (ccs*C+cinvs*I)+ EE_G   ;
-	      Y = phi_y*( alpha*K+alpha*(1/czcap)*R_K+(1-alpha)*L ) +phi_y*EE_A  ;
-	      PIE = (1/(1+beta*gamma_p))*
-	            ( 
-	            (beta)*(PIE(1)) +(gamma_p)*(PIE(-1)) 
-	            +((1-xi_p)*(1-beta*xi_p)/(xi_p))*(MC)
-	            )  + ETA_P ; 
-	            
-	      MC = alpha*R_K+(1-alpha)*W -EE_A;
-	      W =  (1/(1+beta))*(beta*W(+1)+W(-1))
-                +(beta/(1+beta))*(PIE(+1))
-                -((1+beta*gamma_w)/(1+beta))*(PIE)
-                +(gamma_w/(1+beta))*(PIE(-1))
-                -(1/(1+beta))*(((1-beta*xi_w)*(1-xi_w))/(((1+(((1+lambda_w)*sig_l)/(lambda_w))))*xi_w))*(W-sig_l*L-(sig_c/(1-hab))*(C-hab*C(-1))+EE_L)
-                +ETA_W;
-	      L = R_K*((1+czcap)/czcap)-W+K ;
-
-//	      R = r_dpi*(PIE-PIE(-1))
-//              +(1-rho)*(r_pie*(PIE(-1)-PIE_BAR)+r_y*(Y-YF))
-//              +r_dy*(Y-YF-(Y(-1)-YF(-1)))
-//              +rho*(R(-1)-PIE_BAR)
-//              +PIE_BAR
-//              +ETA_R;
-
-
-	      R = 
-
-r_dpi*(PIE-PIE(-1))
-
-              +(1-rho)*(r_pie*(BIGTHETA)+r_y*(Y-YF))
-              +r_dy*(Y-YF-(Y(-1)-YF(-1)))
-              +rho*(R(-1)-PIE_BAR)
-              +PIE_BAR
-              +ETA_R;
-
-
-          E = E(-1)+E(1)-E+(L-E)*((1-xi_e)*(1-xi_e*beta)/(xi_e));
-          
-          
-          EE_A = (rho_a)*EE_A(-1)  + E_A;
-	      PIE_BAR = rho_pb*PIE_BAR(-1)+ E_PIE_BAR ;
-	      EE_B = rho_b*EE_B(-1) + E_B ;
-	      EE_G = rho_g*EE_G(-1) + E_G ;
-	      EE_L = rho_l*EE_L(-1) + E_L ;
-	      EE_I = rho_i*EE_I(-1) + E_I ;
-	      one = 0*one(-1) ;
-
-		LMP*BIGTHETA(1) = BIGTHETA - (PIE(-1) - PIE_BAR) ; 
-
-end; 
-
- 
-shocks;
-var E_A; stderr 0.598;
-var E_B; stderr 0.336;
-var E_G; stderr 0.325;
-var E_I; stderr 0.085;
-var E_L; stderr 3.520;
-var ETA_P; stderr 0.160;
-var ETA_W; stderr 0.289;
-var ETA_R; stderr 0.081;
-var ETA_Q; stderr 0.604;
-var E_PIE_BAR; stderr 0.017;
-end;
-
-//stoch_simul(irf=20) Y C PIE R W R_K L Q I K ;
-
-// stoch_simul generates what kind of standard errors for the shocks ?
-
-//steady;
-//check;
-//stoch_simul(periods=200,irf=20,simul_seed=3) Y C PIE MC R W R_K E L I ;
-
-//datatomfile('ddd',[]);
-
-// new syntax 
-
-estimated_params;
-// PARAM NAME, INITVAL, LB, UB, PRIOR_SHAPE, PRIOR_P1, PRIOR_P2, PRIOR_P3, PRIOR_P4, JSCALE
-// PRIOR_SHAPE: BETA_PDF, GAMMA_PDF, NORMAL_PDF, INV_GAMMA_PDF
-stderr E_A,0.543,0.01,4,INV_GAMMA_PDF,0.4,2;
-stderr E_PIE_BAR,0.072,0.001,4,INV_GAMMA_PDF,0.02,10;
-stderr E_B,0.2694,0.01,4,INV_GAMMA_PDF,0.2,2;
-stderr E_G,0.3052,0.01,4,INV_GAMMA_PDF,0.3,2;
-stderr E_L,1.4575,0.1,6,INV_GAMMA_PDF,1,2;
-stderr E_I,0.1318,0.01,4,INV_GAMMA_PDF,0.1,2;
-stderr ETA_R,0.1363,0.01,4,INV_GAMMA_PDF,0.1,2;
-stderr ETA_Q,0.4842,0.01,4,INV_GAMMA_PDF,0.4,2;
-stderr ETA_P,0.1731,0.01,4,INV_GAMMA_PDF,0.15,2;
-stderr ETA_W,0.2462,0.1,4,INV_GAMMA_PDF,0.25,2;
-rho_a,.9722,.1,.9999,BETA_PDF,0.85,0.1;
-rho_pb,.85,.1,.999,BETA_PDF,0.85,0.1;
-rho_b,.7647,.1,.99,BETA_PDF,0.85,0.1;
-rho_g,.9502,.1,.9999,BETA_PDF,0.85,0.1;
-rho_l,.9542,.1,.9999,BETA_PDF,0.85,0.1;
-rho_i,.6705,.1,.99,BETA_PDF,0.85,0.1;
-phi_i,5.2083,1,15,NORMAL_PDF,4,1.5;
-sig_c,0.9817,0.25,3,NORMAL_PDF,1,0.375;
-hab,0.5612,0.3,0.95,BETA_PDF,0.7,0.1;
-xi_w,0.7661,0.3,0.9,BETA_PDF,0.75,0.05;
-sig_l,1.7526,0.5,5,NORMAL_PDF,2,0.75;
-xi_p,0.8684,0.3,0.95,BETA_PDF,0.75,0.05;
-xi_e,0.5724,0.1,0.95,BETA_PDF,0.5,0.15;
-gamma_w,0.6202,0.1,0.99,BETA_PDF,0.75,0.15;
-gamma_p,0.6638,0.1,0.99,BETA_PDF,0.75,0.15;
-czcap,0.2516,0.01,2,NORMAL_PDF,0.2,0.075;
-phi_y,1.3011,1.001,2,NORMAL_PDF,1.45,0.125;
-r_pie,1.4616,1.2,2,NORMAL_PDF,1.7,0.1;
-r_dpi,0.1144,0.01,0.5,NORMAL_PDF,0.3,0.1;
-rho,0.8865,0.5,0.99,BETA_PDF,0.8,0.10;
-r_y,0.0571,0.01,0.2,NORMAL_PDF,0.125,0.05;
-r_dy,0.2228,0.05,0.5,NORMAL_PDF,0.0625,0.05;
-end;
-
-varobs Y C I E PIE W R;
-
-//estimation(datafile=rawdata_euromodel_1,presample=40, first_obs=1, nobs=118, lik_init=2, mode_compute=1,mh_replic=0);
-estimation(datafile=rawdata_euromodel_1,presample=40, first_obs=1, nobs=118,mh_jscale=0.2,mh_replic=1000
-//,mode_compute=0,mode_file=sweuromodel_dll_mode
-);
-
-
-//stoch_simul(periods=200,irf=20,simul_seed=3) Y C PIE R W R_K L Q I K ;
-
+//options_.usePartInfo=1;
+
+var MC E EF R_KF QF CF IF YF LF PIEF WF RF R_K Q C I Y L PIE W R EE_A PIE_BAR EE_B EE_G EE_L EE_I KF K one BIGTHETA;    
+
+varexo E_A E_B E_G E_L E_I ETA_R E_PIE_BAR ETA_Q ETA_P ETA_W  ;  
+ 
+parameters 
+xi_e lambda_w alpha czcap beta phi_i tau sig_c hab ccs cinvs phi_y gamma_w xi_w gamma_p xi_p sig_l r_dpi 
+r_pie r_dy r_y rho rho_a rho_pb rho_b rho_g rho_l rho_i LMP  ;
+
+
+
+alpha=.30;
+beta=.99;
+tau=0.025;
+ccs=0.6;
+cinvs=.22;  //% alpha*(tau+ctrend)/R_K   R_K=ctrend/beta-1+tau  
+lambda_w = 0.5;
+phi_i= 6.771;
+sig_c=   1.353; 
+hab=    0.573;    
+xi_w=   0.737;
+sig_l=    2.400;
+xi_p=   0.908;
+xi_e= 0.599;
+gamma_w=    0.763;
+gamma_p=    0.469;
+czcap=    0.169;
+phi_y=    1.408;
+r_pie=     1.684;
+r_dpi=    0.14;
+rho=      0.961;
+r_y=      0.099;
+r_dy=     0.159;
+rho_a=    0.823;
+rho_b=    0.855;
+rho_g=    0.949;
+rho_l=   0.889;
+rho_i=   0.927;
+rho_pb=  0.924;
+LMP = 0.0 ; //NEW.
+
+model(linear, use_dll); 
+          CF = (1/(1+hab))*(CF(1)+hab*CF(-1))-((1-hab)/((1+hab)*sig_c))*(RF-PIEF(1)-EE_B) ;
+	      0 =  alpha*R_KF+(1-alpha)*WF -EE_A ;
+          PIEF = 0*one;
+	      IF = (1/(1+beta))* ((  IF(-1) + beta*(IF(1)))+(1/phi_i)*QF)+0*ETA_Q+EE_I ;
+	      QF = -(RF-PIEF(1))+(1-beta*(1-tau))*((0+czcap)/czcap)*R_KF(1)+beta*(1-tau)*QF(1) +0*EE_I ;
+          KF =  (1-tau)*KF(-1)+tau*IF(-1) ;
+	      YF = (ccs*CF+cinvs*IF)+EE_G  ;
+
+	      YF = 1*phi_y*( alpha*KF+alpha*(1/czcap)*R_KF+(1-alpha)*LF+EE_A ) ;
+	      WF = (sig_c/(1-hab))*(CF-hab*CF(-1)) + sig_l*LF - EE_L ;
+	      LF = R_KF*((1+czcap)/czcap)-WF+KF ;
+          EF = EF(-1)+EF(1)-EF+(LF-EF)*((1-xi_e)*(1-xi_e*beta)/(xi_e));
+         
+	      C = (hab/(1+hab))*C(-1)+(1/(1+hab))*C(1)-((1-hab)/((1+hab)*sig_c))*(R-PIE(1)-EE_B) ;
+	      I = (1/(1+beta))* ((  I(-1) + beta*(I(1)))+(1/phi_i)*Q )+1*ETA_Q+1*EE_I ;
+	      Q = -(R-PIE(1))+(1-beta*(1-tau))*((0+czcap)/czcap)*R_K(1)+beta*(1-tau)*Q(1) +EE_I*0+0*ETA_Q ;
+	      K =  (1-tau)*K(-1)+tau*I(-1) ;
+	      Y = (ccs*C+cinvs*I)+ EE_G   ;
+	      Y = phi_y*( alpha*K+alpha*(1/czcap)*R_K+(1-alpha)*L ) +phi_y*EE_A  ;
+	      PIE = (1/(1+beta*gamma_p))*
+	            ( 
+	            (beta)*(PIE(1)) +(gamma_p)*(PIE(-1)) 
+	            +((1-xi_p)*(1-beta*xi_p)/(xi_p))*(MC)
+	            )  + ETA_P ; 
+	            
+	      MC = alpha*R_K+(1-alpha)*W -EE_A;
+	      W =  (1/(1+beta))*(beta*W(+1)+W(-1))
+                +(beta/(1+beta))*(PIE(+1))
+                -((1+beta*gamma_w)/(1+beta))*(PIE)
+                +(gamma_w/(1+beta))*(PIE(-1))
+                -(1/(1+beta))*(((1-beta*xi_w)*(1-xi_w))/(((1+(((1+lambda_w)*sig_l)/(lambda_w))))*xi_w))*(W-sig_l*L-(sig_c/(1-hab))*(C-hab*C(-1))+EE_L)
+                +ETA_W;
+	      L = R_K*((1+czcap)/czcap)-W+K ;
+
+//	      R = r_dpi*(PIE-PIE(-1))
+//              +(1-rho)*(r_pie*(PIE(-1)-PIE_BAR)+r_y*(Y-YF))
+//              +r_dy*(Y-YF-(Y(-1)-YF(-1)))
+//              +rho*(R(-1)-PIE_BAR)
+//              +PIE_BAR
+//              +ETA_R;
+
+
+	      R = 
+
+r_dpi*(PIE-PIE(-1))
+
+              +(1-rho)*(r_pie*(BIGTHETA)+r_y*(Y-YF))
+              +r_dy*(Y-YF-(Y(-1)-YF(-1)))
+              +rho*(R(-1)-PIE_BAR)
+              +PIE_BAR
+              +ETA_R;
+
+
+          E = E(-1)+E(1)-E+(L-E)*((1-xi_e)*(1-xi_e*beta)/(xi_e));
+          
+          
+          EE_A = (rho_a)*EE_A(-1)  + E_A;
+	      PIE_BAR = rho_pb*PIE_BAR(-1)+ E_PIE_BAR ;
+	      EE_B = rho_b*EE_B(-1) + E_B ;
+	      EE_G = rho_g*EE_G(-1) + E_G ;
+	      EE_L = rho_l*EE_L(-1) + E_L ;
+	      EE_I = rho_i*EE_I(-1) + E_I ;
+	      one = 0*one(-1) ;
+
+		LMP*BIGTHETA(1) = BIGTHETA - (PIE(-1) - PIE_BAR) ; 
+
+end; 
+
+ 
+shocks;
+var E_A; stderr 0.598;
+var E_B; stderr 0.336;
+var E_G; stderr 0.325;
+var E_I; stderr 0.085;
+var E_L; stderr 3.520;
+var ETA_P; stderr 0.160;
+var ETA_W; stderr 0.289;
+var ETA_R; stderr 0.081;
+var ETA_Q; stderr 0.604;
+var E_PIE_BAR; stderr 0.017;
+end;
+
+//stoch_simul(irf=20) Y C PIE R W R_K L Q I K ;
+
+// stoch_simul generates what kind of standard errors for the shocks ?
+
+//steady;
+//check;
+//stoch_simul(periods=200,irf=20,simul_seed=3) Y C PIE MC R W R_K E L I ;
+
+//datatomfile('ddd',[]);
+
+// new syntax 
+
+estimated_params;
+// PARAM NAME, INITVAL, LB, UB, PRIOR_SHAPE, PRIOR_P1, PRIOR_P2, PRIOR_P3, PRIOR_P4, JSCALE
+// PRIOR_SHAPE: BETA_PDF, GAMMA_PDF, NORMAL_PDF, INV_GAMMA_PDF
+stderr E_A,0.543,0.01,4,INV_GAMMA_PDF,0.4,2;
+stderr E_PIE_BAR,0.072,0.001,4,INV_GAMMA_PDF,0.02,10;
+stderr E_B,0.2694,0.01,4,INV_GAMMA_PDF,0.2,2;
+stderr E_G,0.3052,0.01,4,INV_GAMMA_PDF,0.3,2;
+stderr E_L,1.4575,0.1,6,INV_GAMMA_PDF,1,2;
+stderr E_I,0.1318,0.01,4,INV_GAMMA_PDF,0.1,2;
+stderr ETA_R,0.1363,0.01,4,INV_GAMMA_PDF,0.1,2;
+stderr ETA_Q,0.4842,0.01,4,INV_GAMMA_PDF,0.4,2;
+stderr ETA_P,0.1731,0.01,4,INV_GAMMA_PDF,0.15,2;
+stderr ETA_W,0.2462,0.1,4,INV_GAMMA_PDF,0.25,2;
+rho_a,.9722,.1,.9999,BETA_PDF,0.85,0.1;
+rho_pb,.85,.1,.999,BETA_PDF,0.85,0.1;
+rho_b,.7647,.1,.99,BETA_PDF,0.85,0.1;
+rho_g,.9502,.1,.9999,BETA_PDF,0.85,0.1;
+rho_l,.9542,.1,.9999,BETA_PDF,0.85,0.1;
+rho_i,.6705,.1,.99,BETA_PDF,0.85,0.1;
+phi_i,5.2083,1,15,NORMAL_PDF,4,1.5;
+sig_c,0.9817,0.25,3,NORMAL_PDF,1,0.375;
+hab,0.5612,0.3,0.95,BETA_PDF,0.7,0.1;
+xi_w,0.7661,0.3,0.9,BETA_PDF,0.75,0.05;
+sig_l,1.7526,0.5,5,NORMAL_PDF,2,0.75;
+xi_p,0.8684,0.3,0.95,BETA_PDF,0.75,0.05;
+xi_e,0.5724,0.1,0.95,BETA_PDF,0.5,0.15;
+gamma_w,0.6202,0.1,0.99,BETA_PDF,0.75,0.15;
+gamma_p,0.6638,0.1,0.99,BETA_PDF,0.75,0.15;
+czcap,0.2516,0.01,2,NORMAL_PDF,0.2,0.075;
+phi_y,1.3011,1.001,2,NORMAL_PDF,1.45,0.125;
+r_pie,1.4616,1.2,2,NORMAL_PDF,1.7,0.1;
+r_dpi,0.1144,0.01,0.5,NORMAL_PDF,0.3,0.1;
+rho,0.8865,0.5,0.99,BETA_PDF,0.8,0.10;
+r_y,0.0571,0.01,0.2,NORMAL_PDF,0.125,0.05;
+r_dy,0.2228,0.05,0.5,NORMAL_PDF,0.0625,0.05;
+end;
+
+varobs Y C I E PIE W R;
+
+//estimation(datafile=rawdata_euromodel_1,presample=40, first_obs=1, nobs=118, lik_init=2, mode_compute=1,mh_replic=0);
+estimation(datafile=rawdata_euromodel_1,presample=40, first_obs=1, nobs=118,mh_jscale=0.2,mh_replic=1000
+//,mode_compute=0,mode_file=sweuromodel_dll_mode
+);
+
+
+//stoch_simul(periods=200,irf=20,simul_seed=3) Y C PIE R W R_K L Q I K ;
+
diff --git a/mex/sources/estimation/tests/rawdata_euromodel_1.m b/mex/sources/estimation/tests/rawdata_euromodel_1.m
index cde44abc94..25bbc92414 100644
--- a/mex/sources/estimation/tests/rawdata_euromodel_1.m
+++ b/mex/sources/estimation/tests/rawdata_euromodel_1.m
@@ -1,967 +1,967 @@
-C =[
-   -7.4073
-   -6.1860
-   -6.5983
-   -5.6088
-   -5.0547
-   -4.4774
-   -3.8081
-   -3.8425
-   -2.4178
-   -1.9835
-   -1.0395
-   -0.1583
-   -0.0397
-    0.3505
-   -0.1879
-   -0.0067
-    0.0478
-   -1.2247
-   -1.4349
-   -0.7973
-   -0.0461
-    0.5844
-    1.1372
-    1.3801
-    1.8023
-    2.2972
-    2.0469
-    2.5435
-    2.8169
-    3.2007
-    2.6705
-    3.0518
-    3.2445
-    3.8443
-    3.8525
-    4.9494
-    4.2770
-    4.9532
-    5.1441
-    3.7124
-    3.9880
-    3.6926
-    2.6005
-    1.8679
-    1.9085
-    1.5563
-    1.2308
-    0.3264
-   -0.2208
-   -0.2483
-   -0.4082
-   -1.0315
-   -1.6030
-   -1.5499
-   -1.3777
-   -2.1675
-   -2.5138
-   -2.8820
-   -2.6958
-   -2.4719
-   -1.9854
-   -1.7954
-   -2.2362
-   -1.0595
-   -0.8808
-   -0.8548
-   -1.2839
-   -0.1363
-    0.2104
-    0.8810
-    0.3555
-    0.4766
-    1.3269
-    1.4506
-    1.4308
-    1.6263
-    1.9842
-    2.3948
-    2.8710
-    3.0177
-    2.9305
-    3.1739
-    3.7380
-    3.8285
-    3.3342
-    3.7447
-    3.7830
-    3.1039
-    2.8413
-    3.0338
-    0.3669
-    0.0847
-    0.0104
-    0.2115
-   -0.6649
-   -0.9625
-   -0.7330
-   -0.8664
-   -1.4441
-   -1.0179
-   -1.2729
-   -1.9539
-   -1.4427
-   -2.0371
-   -1.9764
-   -2.5654
-   -2.8570
-   -2.5842
-   -3.0427
-   -2.8312
-   -2.3320
-   -2.2768
-   -2.1816
-   -2.1043
-   -1.8969
-   -2.2388
-   -2.1679
-   -2.1172
-];
-
-E =[
-    0.6263
-    0.7368
-    0.7477
-    1.0150
-    0.6934
-    0.4135
-    0.3845
-    0.2380
-    0.2853
-    0.5999
-    0.8622
-    1.2116
-    1.4921
-    1.5816
-    1.7259
-    1.6276
-    1.2422
-    0.8084
-    0.4710
-   -0.3704
-   -0.6427
-   -0.5323
-   -0.5562
-   -0.3651
-   -0.4356
-   -0.7164
-   -0.5816
-   -0.4635
-   -0.8456
-   -0.9708
-   -0.7138
-   -0.7499
-   -0.6941
-   -0.6656
-   -0.2912
-   -0.1650
-    0.0774
-    0.2307
-    0.4484
-    0.4942
-    0.4653
-    0.2196
-    0.1736
-   -0.1595
-   -0.3918
-   -0.4611
-   -0.8493
-   -0.7384
-   -1.0604
-   -1.2166
-   -1.7187
-   -1.6932
-   -1.7830
-   -1.7035
-   -2.2079
-   -2.3769
-   -2.2511
-   -2.1093
-   -2.4638
-   -2.4027
-   -2.1313
-   -1.9199
-   -1.7941
-   -1.4661
-   -1.2269
-   -1.0392
-   -1.0725
-   -0.7156
-   -0.4778
-   -0.4233
-   -0.0409
-    0.1620
-    0.4280
-    0.5873
-    1.0323
-    1.3420
-    1.6902
-    2.0680
-    2.8219
-    3.2511
-    3.2930
-    3.5633
-    3.8992
-    3.6874
-    3.2849
-    3.1614
-    2.6221
-    2.5067
-    1.9223
-    1.1777
-    0.4483
-   -0.0661
-   -0.4424
-   -0.9000
-   -1.1478
-   -1.2047
-   -1.1412
-   -1.2383
-   -1.1048
-   -0.9716
-   -0.9287
-   -1.0057
-   -1.0827
-   -1.0200
-   -1.0072
-   -1.1740
-   -1.2809
-   -1.1086
-   -0.9866
-   -0.8947
-   -0.5875
-   -0.2329
-    0.1493
-    0.4906
-    0.8400
-    1.0720
-    1.2648
-    1.5431
-];
-
-I =[
-    2.6617
-    2.4325
-    1.9592
-    3.2530
-    2.9949
-    3.7918
-    4.7444
-    4.8289
-    5.5983
-    7.8923
-    9.4297
-    9.5010
-   10.0150
-   10.0413
-    9.6046
-    6.4766
-    5.9647
-    3.0114
-    0.5683
-   -2.1226
-   -2.1855
-   -0.8329
-   -1.5207
-   -1.3419
-   -1.7897
-   -0.1476
-    0.4675
-   -1.6516
-   -1.5419
-   -1.3050
-   -1.2451
-   -0.7815
-   -0.7796
-   -0.3612
-   -2.4072
-    1.1162
-    1.1383
-    3.4132
-    5.0356
-    2.8016
-    2.1734
-    0.9366
-   -0.7050
-   -1.5021
-   -2.9868
-   -6.0237
-   -6.2589
-   -6.9138
-   -8.2340
-   -9.2589
-   -9.2465
-   -9.6988
-   -9.7782
-  -10.5645
-  -10.7544
-  -13.1583
-  -12.2718
-  -12.0131
-  -13.5983
-  -12.3579
-  -10.9146
-  -11.1572
-  -12.4935
-   -9.4393
-   -8.5535
-   -7.3723
-  -10.0169
-   -6.6088
-   -5.2045
-   -4.1024
-   -2.8472
-   -1.3139
-    0.0477
-    1.5629
-    3.6947
-    4.0327
-    4.1320
-    7.1400
-    9.1036
-    8.5609
-    7.6576
-    8.8022
-    8.9611
-   10.0871
-    9.4797
-    9.3964
-   10.0363
-    8.6340
-    6.6522
-    4.4471
-    0.2854
-   -2.1879
-   -2.9879
-   -4.1021
-   -2.7713
-   -2.2281
-   -1.2908
-   -0.3250
-    0.6534
-    0.3942
-    0.3534
-   -0.1532
-   -1.7936
-    0.4909
-    0.3634
-    0.4290
-   -0.9709
-    0.1942
-    0.6103
-    1.4426
-    2.7225
-    1.7525
-    3.2780
-    3.5985
-    4.9011
-    5.3312
-    6.4402
-    6.6529
-];
-
-L =[
-    0.6263
-    0.7368
-    0.7477
-    1.0150
-    0.6934
-    0.4135
-    0.3845
-    0.2380
-    0.2853
-    0.5999
-    0.8622
-    1.2116
-    1.4921
-    1.5816
-    1.7259
-    1.6276
-    1.2422
-    0.8084
-    0.4710
-   -0.3704
-   -0.6427
-   -0.5323
-   -0.5562
-   -0.3651
-   -0.4356
-   -0.7164
-   -0.5816
-   -0.4635
-   -0.8456
-   -0.9708
-   -0.7138
-   -0.7499
-   -0.6941
-   -0.6656
-   -0.2912
-   -0.1650
-    0.0774
-    0.2307
-    0.4484
-    0.4942
-    0.4653
-    0.2196
-    0.1736
-   -0.1595
-   -0.3918
-   -0.4611
-   -0.8493
-   -0.7384
-   -1.0604
-   -1.2166
-   -1.7187
-   -1.6932
-   -1.7830
-   -1.7035
-   -2.2079
-   -2.3769
-   -2.2511
-   -2.1093
-   -2.4638
-   -2.4027
-   -2.1313
-   -1.9199
-   -1.7941
-   -1.4661
-   -1.2269
-   -1.0392
-   -1.0725
-   -0.7156
-   -0.4778
-   -0.4233
-   -0.0409
-    0.1620
-    0.4280
-    0.5873
-    1.0323
-    1.3420
-    1.6902
-    2.0680
-    2.8219
-    3.2511
-    3.2930
-    3.5633
-    3.8992
-    3.6874
-    3.2849
-    3.1614
-    2.6221
-    2.5067
-    1.9223
-    1.1777
-    0.4483
-   -0.0661
-   -0.4424
-   -0.9000
-   -1.1478
-   -1.2047
-   -1.1412
-   -1.2383
-   -1.1048
-   -0.9716
-   -0.9287
-   -1.0057
-   -1.0827
-   -1.0200
-   -1.0072
-   -1.1740
-   -1.2809
-   -1.1086
-   -0.9866
-   -0.8947
-   -0.5875
-   -0.2329
-    0.1493
-    0.4906
-    0.8400
-    1.0720
-    1.2648
-    1.5431
-];
-
-PIE =[
-   -1.0113
-   -0.8305
-    0.2332
-   -0.8746
-   -0.7978
-   -0.9220
-   -0.2487
-   -0.7749
-   -0.5460
-   -0.5347
-    0.5050
-   -0.0334
-    0.6756
-    0.8791
-    0.7267
-    1.0997
-    1.1750
-    1.1927
-    0.4420
-    0.5357
-    0.0345
-    0.0196
-    0.3371
-    0.9379
-    1.2160
-    0.3393
-    0.5813
-    0.7410
-    0.3374
-    0.2616
-    0.4025
-    0.4799
-    0.5981
-   -0.1523
-    0.4458
-    0.2182
-    0.9793
-    0.7562
-    1.0064
-    0.8203
-    0.6966
-    0.3352
-    0.6581
-    0.6111
-    0.9833
-    1.1991
-    0.9562
-    0.3868
-    0.2939
-    0.2471
-    0.8331
-    0.0715
-    0.3910
-    0.3301
-    0.2547
-   -0.2702
-   -0.2998
-   -0.1953
-   -0.2293
-   -0.3284
-    0.0480
-   -0.0374
-    0.3253
-   -0.3434
-   -0.3892
-   -0.7178
-   -0.4758
-   -0.6794
-   -0.8505
-   -0.3512
-   -0.4436
-   -0.5101
-   -0.4574
-   -0.2696
-   -0.1047
-   -0.5745
-   -0.2989
-   -0.0063
-    0.0088
-   -0.1184
-   -0.1506
-   -0.4073
-    0.2674
-    0.2896
-    0.0669
-    0.1166
-   -0.1699
-   -0.2518
-   -0.0562
-   -0.3269
-   -0.0703
-   -0.1046
-   -0.4888
-   -0.3524
-   -0.2485
-   -0.5870
-   -0.4546
-   -0.3970
-   -0.2353
-   -0.0352
-   -0.2171
-   -0.3754
-   -0.4322
-   -0.4572
-   -0.4903
-   -0.4518
-   -0.6435
-   -0.6304
-   -0.4148
-   -0.2892
-   -0.4318
-   -0.6010
-   -0.4148
-   -0.4315
-   -0.3531
-   -0.8053
-   -0.4680
-   -0.4263
-];
-
-R =[
-   -1.0750
-   -1.1540
-   -1.3682
-   -1.4569
-   -1.3490
-   -1.4011
-   -1.6486
-   -1.6968
-   -1.6976
-   -1.2567
-   -1.1392
-   -0.7783
-   -0.3021
-   -0.0435
-    0.0066
-   -0.0043
-    0.1029
-   -0.0628
-   -0.5358
-   -0.9627
-   -1.1079
-   -1.0918
-   -0.9966
-   -0.6223
-   -0.3616
-   -0.2711
-   -0.0997
-   -0.2810
-   -0.3710
-   -0.3167
-   -0.5301
-   -0.5826
-   -0.3194
-   -0.2713
-   -0.5287
-   -0.2432
-    0.1098
-    0.5349
-    0.7094
-    0.8415
-    0.6226
-    0.7376
-    0.9316
-    1.4370
-    1.5853
-    1.4267
-    1.1783
-    1.2046
-    0.9689
-    0.7918
-    0.6315
-    0.5950
-    0.6853
-    0.7171
-    0.5887
-    0.4873
-    0.4027
-    0.3489
-    0.2934
-    0.3060
-    0.1741
-    0.0348
-    0.0771
-   -0.1005
-   -0.1518
-   -0.1104
-   -0.0681
-   -0.0059
-    0.0256
-    0.0404
-   -0.1721
-   -0.2002
-    0.0015
-    0.1249
-    0.3738
-    0.4320
-    0.5579
-    0.8186
-    0.8727
-    0.7356
-    0.7243
-    0.8635
-    0.9058
-    0.7656
-    0.7936
-    0.8631
-    0.9074
-    0.9547
-    1.2045
-    1.0850
-    0.9178
-    0.5242
-    0.3178
-    0.1472
-    0.0227
-   -0.0799
-   -0.0611
-   -0.0140
-    0.1132
-    0.1774
-    0.0782
-    0.0436
-   -0.1596
-   -0.2691
-   -0.2895
-   -0.3791
-   -0.4020
-   -0.4166
-   -0.4037
-   -0.3636
-   -0.4075
-   -0.4311
-   -0.4470
-   -0.5111
-   -0.6274
-   -0.7261
-   -0.6974
-   -0.5012
-];
-
-W =[
-  -14.8791
-  -13.2300
-  -13.5037
-  -13.0249
-  -11.2546
-  -10.0148
-   -8.8586
-   -8.5739
-   -7.7851
-   -6.7136
-   -5.5878
-   -4.6881
-   -3.8039
-   -3.0366
-   -2.7342
-   -1.3135
-   -0.7387
-   -0.1131
-   -0.2769
-    0.8696
-    1.8855
-    2.3667
-    2.4942
-    3.2049
-    3.9682
-    5.1500
-    4.7047
-    4.7827
-    5.3377
-    5.6614
-    5.2813
-    5.2967
-    5.5175
-    6.1526
-    5.6627
-    6.0694
-    6.5824
-    6.9032
-    6.7849
-    6.6896
-    6.6201
-    6.9933
-    5.8959
-    6.7419
-    6.9999
-    6.4009
-    5.5083
-    5.1054
-    5.2813
-    4.5790
-    3.9589
-    3.8599
-    3.8978
-    2.7957
-    3.2480
-    1.4634
-    1.9219
-    1.8398
-    1.9279
-    1.8316
-    1.6092
-    1.2741
-    0.2031
-   -0.0236
-   -0.1004
-   -0.3034
-   -1.0273
-   -0.2205
-    0.0458
-    0.2386
-   -0.0977
-   -0.3145
-   -0.1416
-   -0.7009
-   -0.9082
-   -0.8802
-   -0.5644
-   -0.5852
-   -0.5346
-    0.0652
-    0.1301
-    0.3444
-   -0.3592
-    0.8096
-    0.9644
-    1.0289
-    1.2781
-    1.2298
-    2.2134
-    2.0808
-    0.4925
-    0.6506
-    0.5531
-    0.2456
-   -0.5351
-   -0.8183
-   -0.8967
-   -0.7268
-   -1.0738
-   -1.2844
-   -1.4338
-   -1.6995
-   -1.7085
-   -2.2889
-   -2.1018
-   -2.4273
-   -2.4609
-   -2.1407
-   -2.3847
-   -3.1689
-   -4.5581
-   -4.1027
-   -4.2436
-   -4.8836
-   -5.9660
-   -4.9971
-   -5.2386
-   -5.6618
-];
-
-Y =[
-   -4.9347
-   -4.6205
-   -5.2198
-   -4.5937
-   -3.8015
-   -3.6643
-   -2.7239
-   -2.7524
-   -2.0634
-   -1.0112
-    0.0530
-    0.7623
-    1.7927
-    2.1486
-    2.4866
-    2.1456
-    2.1671
-   -0.0254
-   -1.6716
-   -1.9673
-   -1.6109
-   -1.0292
-   -0.1222
-    0.7329
-    1.1234
-    2.0603
-    1.7998
-    1.4820
-    1.1732
-    1.6424
-    1.5382
-    2.1399
-    2.0127
-    2.7210
-    2.4966
-    3.5249
-    3.6237
-    4.2011
-    4.5634
-    3.3442
-    2.7761
-    1.9812
-    1.3779
-    1.4616
-    1.3029
-    0.7594
-    0.3695
-    0.0832
-   -0.8118
-   -1.4557
-   -1.4850
-   -1.2346
-   -1.5696
-   -1.3785
-   -0.7682
-   -2.0308
-   -1.7778
-   -1.7801
-   -2.1711
-   -1.7469
-   -1.3413
-   -1.3352
-   -2.4390
-   -1.2125
-   -1.1695
-   -1.0891
-   -2.4753
-   -1.3503
-   -0.9412
-   -0.1470
-    0.0026
-    0.1108
-    0.6890
-    1.3520
-    1.6018
-    2.0667
-    1.7625
-    2.6658
-    3.4048
-    3.2507
-    3.4251
-    3.2174
-    3.1903
-    3.3396
-    3.1358
-    2.8625
-    3.3546
-    2.4609
-    1.9534
-    0.9962
-   -0.7904
-   -1.1672
-   -1.2586
-   -1.3593
-   -1.3443
-   -0.9413
-   -0.6023
-   -0.4516
-   -0.5129
-   -0.8741
-   -1.0784
-   -1.4091
-   -1.3627
-   -1.5731
-   -1.6037
-   -1.8814
-   -2.1482
-   -1.3597
-   -1.1855
-   -1.1122
-   -0.8424
-   -0.9747
-   -1.1385
-   -1.4548
-   -1.4284
-   -1.4633
-   -1.0621
-   -0.7871
-];
+C =[
+   -7.4073
+   -6.1860
+   -6.5983
+   -5.6088
+   -5.0547
+   -4.4774
+   -3.8081
+   -3.8425
+   -2.4178
+   -1.9835
+   -1.0395
+   -0.1583
+   -0.0397
+    0.3505
+   -0.1879
+   -0.0067
+    0.0478
+   -1.2247
+   -1.4349
+   -0.7973
+   -0.0461
+    0.5844
+    1.1372
+    1.3801
+    1.8023
+    2.2972
+    2.0469
+    2.5435
+    2.8169
+    3.2007
+    2.6705
+    3.0518
+    3.2445
+    3.8443
+    3.8525
+    4.9494
+    4.2770
+    4.9532
+    5.1441
+    3.7124
+    3.9880
+    3.6926
+    2.6005
+    1.8679
+    1.9085
+    1.5563
+    1.2308
+    0.3264
+   -0.2208
+   -0.2483
+   -0.4082
+   -1.0315
+   -1.6030
+   -1.5499
+   -1.3777
+   -2.1675
+   -2.5138
+   -2.8820
+   -2.6958
+   -2.4719
+   -1.9854
+   -1.7954
+   -2.2362
+   -1.0595
+   -0.8808
+   -0.8548
+   -1.2839
+   -0.1363
+    0.2104
+    0.8810
+    0.3555
+    0.4766
+    1.3269
+    1.4506
+    1.4308
+    1.6263
+    1.9842
+    2.3948
+    2.8710
+    3.0177
+    2.9305
+    3.1739
+    3.7380
+    3.8285
+    3.3342
+    3.7447
+    3.7830
+    3.1039
+    2.8413
+    3.0338
+    0.3669
+    0.0847
+    0.0104
+    0.2115
+   -0.6649
+   -0.9625
+   -0.7330
+   -0.8664
+   -1.4441
+   -1.0179
+   -1.2729
+   -1.9539
+   -1.4427
+   -2.0371
+   -1.9764
+   -2.5654
+   -2.8570
+   -2.5842
+   -3.0427
+   -2.8312
+   -2.3320
+   -2.2768
+   -2.1816
+   -2.1043
+   -1.8969
+   -2.2388
+   -2.1679
+   -2.1172
+];
+
+E =[
+    0.6263
+    0.7368
+    0.7477
+    1.0150
+    0.6934
+    0.4135
+    0.3845
+    0.2380
+    0.2853
+    0.5999
+    0.8622
+    1.2116
+    1.4921
+    1.5816
+    1.7259
+    1.6276
+    1.2422
+    0.8084
+    0.4710
+   -0.3704
+   -0.6427
+   -0.5323
+   -0.5562
+   -0.3651
+   -0.4356
+   -0.7164
+   -0.5816
+   -0.4635
+   -0.8456
+   -0.9708
+   -0.7138
+   -0.7499
+   -0.6941
+   -0.6656
+   -0.2912
+   -0.1650
+    0.0774
+    0.2307
+    0.4484
+    0.4942
+    0.4653
+    0.2196
+    0.1736
+   -0.1595
+   -0.3918
+   -0.4611
+   -0.8493
+   -0.7384
+   -1.0604
+   -1.2166
+   -1.7187
+   -1.6932
+   -1.7830
+   -1.7035
+   -2.2079
+   -2.3769
+   -2.2511
+   -2.1093
+   -2.4638
+   -2.4027
+   -2.1313
+   -1.9199
+   -1.7941
+   -1.4661
+   -1.2269
+   -1.0392
+   -1.0725
+   -0.7156
+   -0.4778
+   -0.4233
+   -0.0409
+    0.1620
+    0.4280
+    0.5873
+    1.0323
+    1.3420
+    1.6902
+    2.0680
+    2.8219
+    3.2511
+    3.2930
+    3.5633
+    3.8992
+    3.6874
+    3.2849
+    3.1614
+    2.6221
+    2.5067
+    1.9223
+    1.1777
+    0.4483
+   -0.0661
+   -0.4424
+   -0.9000
+   -1.1478
+   -1.2047
+   -1.1412
+   -1.2383
+   -1.1048
+   -0.9716
+   -0.9287
+   -1.0057
+   -1.0827
+   -1.0200
+   -1.0072
+   -1.1740
+   -1.2809
+   -1.1086
+   -0.9866
+   -0.8947
+   -0.5875
+   -0.2329
+    0.1493
+    0.4906
+    0.8400
+    1.0720
+    1.2648
+    1.5431
+];
+
+I =[
+    2.6617
+    2.4325
+    1.9592
+    3.2530
+    2.9949
+    3.7918
+    4.7444
+    4.8289
+    5.5983
+    7.8923
+    9.4297
+    9.5010
+   10.0150
+   10.0413
+    9.6046
+    6.4766
+    5.9647
+    3.0114
+    0.5683
+   -2.1226
+   -2.1855
+   -0.8329
+   -1.5207
+   -1.3419
+   -1.7897
+   -0.1476
+    0.4675
+   -1.6516
+   -1.5419
+   -1.3050
+   -1.2451
+   -0.7815
+   -0.7796
+   -0.3612
+   -2.4072
+    1.1162
+    1.1383
+    3.4132
+    5.0356
+    2.8016
+    2.1734
+    0.9366
+   -0.7050
+   -1.5021
+   -2.9868
+   -6.0237
+   -6.2589
+   -6.9138
+   -8.2340
+   -9.2589
+   -9.2465
+   -9.6988
+   -9.7782
+  -10.5645
+  -10.7544
+  -13.1583
+  -12.2718
+  -12.0131
+  -13.5983
+  -12.3579
+  -10.9146
+  -11.1572
+  -12.4935
+   -9.4393
+   -8.5535
+   -7.3723
+  -10.0169
+   -6.6088
+   -5.2045
+   -4.1024
+   -2.8472
+   -1.3139
+    0.0477
+    1.5629
+    3.6947
+    4.0327
+    4.1320
+    7.1400
+    9.1036
+    8.5609
+    7.6576
+    8.8022
+    8.9611
+   10.0871
+    9.4797
+    9.3964
+   10.0363
+    8.6340
+    6.6522
+    4.4471
+    0.2854
+   -2.1879
+   -2.9879
+   -4.1021
+   -2.7713
+   -2.2281
+   -1.2908
+   -0.3250
+    0.6534
+    0.3942
+    0.3534
+   -0.1532
+   -1.7936
+    0.4909
+    0.3634
+    0.4290
+   -0.9709
+    0.1942
+    0.6103
+    1.4426
+    2.7225
+    1.7525
+    3.2780
+    3.5985
+    4.9011
+    5.3312
+    6.4402
+    6.6529
+];
+
+L =[
+    0.6263
+    0.7368
+    0.7477
+    1.0150
+    0.6934
+    0.4135
+    0.3845
+    0.2380
+    0.2853
+    0.5999
+    0.8622
+    1.2116
+    1.4921
+    1.5816
+    1.7259
+    1.6276
+    1.2422
+    0.8084
+    0.4710
+   -0.3704
+   -0.6427
+   -0.5323
+   -0.5562
+   -0.3651
+   -0.4356
+   -0.7164
+   -0.5816
+   -0.4635
+   -0.8456
+   -0.9708
+   -0.7138
+   -0.7499
+   -0.6941
+   -0.6656
+   -0.2912
+   -0.1650
+    0.0774
+    0.2307
+    0.4484
+    0.4942
+    0.4653
+    0.2196
+    0.1736
+   -0.1595
+   -0.3918
+   -0.4611
+   -0.8493
+   -0.7384
+   -1.0604
+   -1.2166
+   -1.7187
+   -1.6932
+   -1.7830
+   -1.7035
+   -2.2079
+   -2.3769
+   -2.2511
+   -2.1093
+   -2.4638
+   -2.4027
+   -2.1313
+   -1.9199
+   -1.7941
+   -1.4661
+   -1.2269
+   -1.0392
+   -1.0725
+   -0.7156
+   -0.4778
+   -0.4233
+   -0.0409
+    0.1620
+    0.4280
+    0.5873
+    1.0323
+    1.3420
+    1.6902
+    2.0680
+    2.8219
+    3.2511
+    3.2930
+    3.5633
+    3.8992
+    3.6874
+    3.2849
+    3.1614
+    2.6221
+    2.5067
+    1.9223
+    1.1777
+    0.4483
+   -0.0661
+   -0.4424
+   -0.9000
+   -1.1478
+   -1.2047
+   -1.1412
+   -1.2383
+   -1.1048
+   -0.9716
+   -0.9287
+   -1.0057
+   -1.0827
+   -1.0200
+   -1.0072
+   -1.1740
+   -1.2809
+   -1.1086
+   -0.9866
+   -0.8947
+   -0.5875
+   -0.2329
+    0.1493
+    0.4906
+    0.8400
+    1.0720
+    1.2648
+    1.5431
+];
+
+PIE =[
+   -1.0113
+   -0.8305
+    0.2332
+   -0.8746
+   -0.7978
+   -0.9220
+   -0.2487
+   -0.7749
+   -0.5460
+   -0.5347
+    0.5050
+   -0.0334
+    0.6756
+    0.8791
+    0.7267
+    1.0997
+    1.1750
+    1.1927
+    0.4420
+    0.5357
+    0.0345
+    0.0196
+    0.3371
+    0.9379
+    1.2160
+    0.3393
+    0.5813
+    0.7410
+    0.3374
+    0.2616
+    0.4025
+    0.4799
+    0.5981
+   -0.1523
+    0.4458
+    0.2182
+    0.9793
+    0.7562
+    1.0064
+    0.8203
+    0.6966
+    0.3352
+    0.6581
+    0.6111
+    0.9833
+    1.1991
+    0.9562
+    0.3868
+    0.2939
+    0.2471
+    0.8331
+    0.0715
+    0.3910
+    0.3301
+    0.2547
+   -0.2702
+   -0.2998
+   -0.1953
+   -0.2293
+   -0.3284
+    0.0480
+   -0.0374
+    0.3253
+   -0.3434
+   -0.3892
+   -0.7178
+   -0.4758
+   -0.6794
+   -0.8505
+   -0.3512
+   -0.4436
+   -0.5101
+   -0.4574
+   -0.2696
+   -0.1047
+   -0.5745
+   -0.2989
+   -0.0063
+    0.0088
+   -0.1184
+   -0.1506
+   -0.4073
+    0.2674
+    0.2896
+    0.0669
+    0.1166
+   -0.1699
+   -0.2518
+   -0.0562
+   -0.3269
+   -0.0703
+   -0.1046
+   -0.4888
+   -0.3524
+   -0.2485
+   -0.5870
+   -0.4546
+   -0.3970
+   -0.2353
+   -0.0352
+   -0.2171
+   -0.3754
+   -0.4322
+   -0.4572
+   -0.4903
+   -0.4518
+   -0.6435
+   -0.6304
+   -0.4148
+   -0.2892
+   -0.4318
+   -0.6010
+   -0.4148
+   -0.4315
+   -0.3531
+   -0.8053
+   -0.4680
+   -0.4263
+];
+
+R =[
+   -1.0750
+   -1.1540
+   -1.3682
+   -1.4569
+   -1.3490
+   -1.4011
+   -1.6486
+   -1.6968
+   -1.6976
+   -1.2567
+   -1.1392
+   -0.7783
+   -0.3021
+   -0.0435
+    0.0066
+   -0.0043
+    0.1029
+   -0.0628
+   -0.5358
+   -0.9627
+   -1.1079
+   -1.0918
+   -0.9966
+   -0.6223
+   -0.3616
+   -0.2711
+   -0.0997
+   -0.2810
+   -0.3710
+   -0.3167
+   -0.5301
+   -0.5826
+   -0.3194
+   -0.2713
+   -0.5287
+   -0.2432
+    0.1098
+    0.5349
+    0.7094
+    0.8415
+    0.6226
+    0.7376
+    0.9316
+    1.4370
+    1.5853
+    1.4267
+    1.1783
+    1.2046
+    0.9689
+    0.7918
+    0.6315
+    0.5950
+    0.6853
+    0.7171
+    0.5887
+    0.4873
+    0.4027
+    0.3489
+    0.2934
+    0.3060
+    0.1741
+    0.0348
+    0.0771
+   -0.1005
+   -0.1518
+   -0.1104
+   -0.0681
+   -0.0059
+    0.0256
+    0.0404
+   -0.1721
+   -0.2002
+    0.0015
+    0.1249
+    0.3738
+    0.4320
+    0.5579
+    0.8186
+    0.8727
+    0.7356
+    0.7243
+    0.8635
+    0.9058
+    0.7656
+    0.7936
+    0.8631
+    0.9074
+    0.9547
+    1.2045
+    1.0850
+    0.9178
+    0.5242
+    0.3178
+    0.1472
+    0.0227
+   -0.0799
+   -0.0611
+   -0.0140
+    0.1132
+    0.1774
+    0.0782
+    0.0436
+   -0.1596
+   -0.2691
+   -0.2895
+   -0.3791
+   -0.4020
+   -0.4166
+   -0.4037
+   -0.3636
+   -0.4075
+   -0.4311
+   -0.4470
+   -0.5111
+   -0.6274
+   -0.7261
+   -0.6974
+   -0.5012
+];
+
+W =[
+  -14.8791
+  -13.2300
+  -13.5037
+  -13.0249
+  -11.2546
+  -10.0148
+   -8.8586
+   -8.5739
+   -7.7851
+   -6.7136
+   -5.5878
+   -4.6881
+   -3.8039
+   -3.0366
+   -2.7342
+   -1.3135
+   -0.7387
+   -0.1131
+   -0.2769
+    0.8696
+    1.8855
+    2.3667
+    2.4942
+    3.2049
+    3.9682
+    5.1500
+    4.7047
+    4.7827
+    5.3377
+    5.6614
+    5.2813
+    5.2967
+    5.5175
+    6.1526
+    5.6627
+    6.0694
+    6.5824
+    6.9032
+    6.7849
+    6.6896
+    6.6201
+    6.9933
+    5.8959
+    6.7419
+    6.9999
+    6.4009
+    5.5083
+    5.1054
+    5.2813
+    4.5790
+    3.9589
+    3.8599
+    3.8978
+    2.7957
+    3.2480
+    1.4634
+    1.9219
+    1.8398
+    1.9279
+    1.8316
+    1.6092
+    1.2741
+    0.2031
+   -0.0236
+   -0.1004
+   -0.3034
+   -1.0273
+   -0.2205
+    0.0458
+    0.2386
+   -0.0977
+   -0.3145
+   -0.1416
+   -0.7009
+   -0.9082
+   -0.8802
+   -0.5644
+   -0.5852
+   -0.5346
+    0.0652
+    0.1301
+    0.3444
+   -0.3592
+    0.8096
+    0.9644
+    1.0289
+    1.2781
+    1.2298
+    2.2134
+    2.0808
+    0.4925
+    0.6506
+    0.5531
+    0.2456
+   -0.5351
+   -0.8183
+   -0.8967
+   -0.7268
+   -1.0738
+   -1.2844
+   -1.4338
+   -1.6995
+   -1.7085
+   -2.2889
+   -2.1018
+   -2.4273
+   -2.4609
+   -2.1407
+   -2.3847
+   -3.1689
+   -4.5581
+   -4.1027
+   -4.2436
+   -4.8836
+   -5.9660
+   -4.9971
+   -5.2386
+   -5.6618
+];
+
+Y =[
+   -4.9347
+   -4.6205
+   -5.2198
+   -4.5937
+   -3.8015
+   -3.6643
+   -2.7239
+   -2.7524
+   -2.0634
+   -1.0112
+    0.0530
+    0.7623
+    1.7927
+    2.1486
+    2.4866
+    2.1456
+    2.1671
+   -0.0254
+   -1.6716
+   -1.9673
+   -1.6109
+   -1.0292
+   -0.1222
+    0.7329
+    1.1234
+    2.0603
+    1.7998
+    1.4820
+    1.1732
+    1.6424
+    1.5382
+    2.1399
+    2.0127
+    2.7210
+    2.4966
+    3.5249
+    3.6237
+    4.2011
+    4.5634
+    3.3442
+    2.7761
+    1.9812
+    1.3779
+    1.4616
+    1.3029
+    0.7594
+    0.3695
+    0.0832
+   -0.8118
+   -1.4557
+   -1.4850
+   -1.2346
+   -1.5696
+   -1.3785
+   -0.7682
+   -2.0308
+   -1.7778
+   -1.7801
+   -2.1711
+   -1.7469
+   -1.3413
+   -1.3352
+   -2.4390
+   -1.2125
+   -1.1695
+   -1.0891
+   -2.4753
+   -1.3503
+   -0.9412
+   -0.1470
+    0.0026
+    0.1108
+    0.6890
+    1.3520
+    1.6018
+    2.0667
+    1.7625
+    2.6658
+    3.4048
+    3.2507
+    3.4251
+    3.2174
+    3.1903
+    3.3396
+    3.1358
+    2.8625
+    3.3546
+    2.4609
+    1.9534
+    0.9962
+   -0.7904
+   -1.1672
+   -1.2586
+   -1.3593
+   -1.3443
+   -0.9413
+   -0.6023
+   -0.4516
+   -0.5129
+   -0.8741
+   -1.0784
+   -1.4091
+   -1.3627
+   -1.5731
+   -1.6037
+   -1.8814
+   -2.1482
+   -1.3597
+   -1.1855
+   -1.1122
+   -0.8424
+   -0.9747
+   -1.1385
+   -1.4548
+   -1.4284
+   -1.4633
+   -1.0621
+   -0.7871
+];
diff --git a/mex/sources/estimation/tests/sweuromodel_dll.mod b/mex/sources/estimation/tests/sweuromodel_dll.mod
index 363e310883..658dec00ad 100644
--- a/mex/sources/estimation/tests/sweuromodel_dll.mod
+++ b/mex/sources/estimation/tests/sweuromodel_dll.mod
@@ -1,182 +1,182 @@
-//options_.usePartInfo=1;
-
-var MC E EF R_KF QF CF IF YF LF PIEF WF RF R_K Q C I Y L PIE W R EE_A PIE_BAR EE_B EE_G EE_L EE_I KF K one BIGTHETA;    
-
-varexo E_A E_B E_G E_L E_I ETA_R E_PIE_BAR ETA_Q ETA_P ETA_W  ;  
- 
-parameters 
-xi_e lambda_w alpha czcap beta phi_i tau sig_c hab ccs cinvs phi_y gamma_w xi_w gamma_p xi_p sig_l r_dpi 
-r_pie r_dy r_y rho rho_a rho_pb rho_b rho_g rho_l rho_i LMP  ;
-
-
-
-alpha=.30;
-beta=.99;
-tau=0.025;
-ccs=0.6;
-cinvs=.22;  //% alpha*(tau+ctrend)/R_K   R_K=ctrend/beta-1+tau  
-lambda_w = 0.5;
-phi_i= 6.771;
-sig_c=   1.353; 
-hab=    0.573;    
-xi_w=   0.737;
-sig_l=    2.400;
-xi_p=   0.908;
-xi_e= 0.599;
-gamma_w=    0.763;
-gamma_p=    0.469;
-czcap=    0.169;
-phi_y=    1.408;
-r_pie=     1.684;
-r_dpi=    0.14;
-rho=      0.961;
-r_y=      0.099;
-r_dy=     0.159;
-rho_a=    0.823;
-rho_b=    0.855;
-rho_g=    0.949;
-rho_l=   0.889;
-rho_i=   0.927;
-rho_pb=  0.924;
-LMP = 0.0 ; //NEW.
-
-model(linear, use_dll); 
-          CF = (1/(1+hab))*(CF(1)+hab*CF(-1))-((1-hab)/((1+hab)*sig_c))*(RF-PIEF(1)-EE_B) ;
-	      0 =  alpha*R_KF+(1-alpha)*WF -EE_A ;
-          PIEF = 0*one;
-	      IF = (1/(1+beta))* ((  IF(-1) + beta*(IF(1)))+(1/phi_i)*QF)+0*ETA_Q+EE_I ;
-	      QF = -(RF-PIEF(1))+(1-beta*(1-tau))*((0+czcap)/czcap)*R_KF(1)+beta*(1-tau)*QF(1) +0*EE_I ;
-          KF =  (1-tau)*KF(-1)+tau*IF(-1) ;
-	      YF = (ccs*CF+cinvs*IF)+EE_G  ;
-
-	      YF = 1*phi_y*( alpha*KF+alpha*(1/czcap)*R_KF+(1-alpha)*LF+EE_A ) ;
-	      WF = (sig_c/(1-hab))*(CF-hab*CF(-1)) + sig_l*LF - EE_L ;
-	      LF = R_KF*((1+czcap)/czcap)-WF+KF ;
-          EF = EF(-1)+EF(1)-EF+(LF-EF)*((1-xi_e)*(1-xi_e*beta)/(xi_e));
-         
-	      C = (hab/(1+hab))*C(-1)+(1/(1+hab))*C(1)-((1-hab)/((1+hab)*sig_c))*(R-PIE(1)-EE_B) ;
-	      I = (1/(1+beta))* ((  I(-1) + beta*(I(1)))+(1/phi_i)*Q )+1*ETA_Q+1*EE_I ;
-	      Q = -(R-PIE(1))+(1-beta*(1-tau))*((0+czcap)/czcap)*R_K(1)+beta*(1-tau)*Q(1) +EE_I*0+0*ETA_Q ;
-	      K =  (1-tau)*K(-1)+tau*I(-1) ;
-	      Y = (ccs*C+cinvs*I)+ EE_G   ;
-	      Y = phi_y*( alpha*K+alpha*(1/czcap)*R_K+(1-alpha)*L ) +phi_y*EE_A  ;
-	      PIE = (1/(1+beta*gamma_p))*
-	            ( 
-	            (beta)*(PIE(1)) +(gamma_p)*(PIE(-1)) 
-	            +((1-xi_p)*(1-beta*xi_p)/(xi_p))*(MC)
-	            )  + ETA_P ; 
-	            
-	      MC = alpha*R_K+(1-alpha)*W -EE_A;
-	      W =  (1/(1+beta))*(beta*W(+1)+W(-1))
-                +(beta/(1+beta))*(PIE(+1))
-                -((1+beta*gamma_w)/(1+beta))*(PIE)
-                +(gamma_w/(1+beta))*(PIE(-1))
-                -(1/(1+beta))*(((1-beta*xi_w)*(1-xi_w))/(((1+(((1+lambda_w)*sig_l)/(lambda_w))))*xi_w))*(W-sig_l*L-(sig_c/(1-hab))*(C-hab*C(-1))+EE_L)
-                +ETA_W;
-	      L = R_K*((1+czcap)/czcap)-W+K ;
-
-//	      R = r_dpi*(PIE-PIE(-1))
-//              +(1-rho)*(r_pie*(PIE(-1)-PIE_BAR)+r_y*(Y-YF))
-//              +r_dy*(Y-YF-(Y(-1)-YF(-1)))
-//              +rho*(R(-1)-PIE_BAR)
-//              +PIE_BAR
-//              +ETA_R;
-
-
-	      R = 
-
-r_dpi*(PIE-PIE(-1))
-
-              +(1-rho)*(r_pie*(BIGTHETA)+r_y*(Y-YF))
-              +r_dy*(Y-YF-(Y(-1)-YF(-1)))
-              +rho*(R(-1)-PIE_BAR)
-              +PIE_BAR
-              +ETA_R;
-
-
-          E = E(-1)+E(1)-E+(L-E)*((1-xi_e)*(1-xi_e*beta)/(xi_e));
-          
-          
-          EE_A = (rho_a)*EE_A(-1)  + E_A;
-	      PIE_BAR = rho_pb*PIE_BAR(-1)+ E_PIE_BAR ;
-	      EE_B = rho_b*EE_B(-1) + E_B ;
-	      EE_G = rho_g*EE_G(-1) + E_G ;
-	      EE_L = rho_l*EE_L(-1) + E_L ;
-	      EE_I = rho_i*EE_I(-1) + E_I ;
-	      one = 0*one(-1) ;
-
-		LMP*BIGTHETA(1) = BIGTHETA - (PIE(-1) - PIE_BAR) ; 
-
-end; 
-
- 
-shocks;
-var E_A; stderr 0.598;
-var E_B; stderr 0.336;
-var E_G; stderr 0.325;
-var E_I; stderr 0.085;
-var E_L; stderr 3.520;
-var ETA_P; stderr 0.160;
-var ETA_W; stderr 0.289;
-var ETA_R; stderr 0.081;
-var ETA_Q; stderr 0.604;
-var E_PIE_BAR; stderr 0.017;
-end;
-
-//stoch_simul(irf=20) Y C PIE R W R_K L Q I K ;
-
-// stoch_simul generates what kind of standard errors for the shocks ?
-
-//steady;
-//check;
-//stoch_simul(periods=200,irf=20,simul_seed=3) Y C PIE MC R W R_K E L I ;
-
-//datatomfile('ddd',[]);
-
-// new syntax 
-
-estimated_params;
-// PARAM NAME, INITVAL, LB, UB, PRIOR_SHAPE, PRIOR_P1, PRIOR_P2, PRIOR_P3, PRIOR_P4, JSCALE
-// PRIOR_SHAPE: BETA_PDF, GAMMA_PDF, NORMAL_PDF, INV_GAMMA_PDF
-stderr E_A,0.543,0.01,4,INV_GAMMA_PDF,0.4,2;
-stderr E_PIE_BAR,0.072,0.001,4,INV_GAMMA_PDF,0.02,10;
-stderr E_B,0.2694,0.01,4,INV_GAMMA_PDF,0.2,2;
-stderr E_G,0.3052,0.01,4,INV_GAMMA_PDF,0.3,2;
-stderr E_L,1.4575,0.1,6,INV_GAMMA_PDF,1,2;
-stderr E_I,0.1318,0.01,4,INV_GAMMA_PDF,0.1,2;
-stderr ETA_R,0.1363,0.01,4,INV_GAMMA_PDF,0.1,2;
-stderr ETA_Q,0.4842,0.01,4,INV_GAMMA_PDF,0.4,2;
-stderr ETA_P,0.1731,0.01,4,INV_GAMMA_PDF,0.15,2;
-stderr ETA_W,0.2462,0.1,4,INV_GAMMA_PDF,0.25,2;
-rho_a,.9722,.1,.9999,BETA_PDF,0.85,0.1;
-rho_pb,.85,.1,.999,BETA_PDF,0.85,0.1;
-rho_b,.7647,.1,.99,BETA_PDF,0.85,0.1;
-rho_g,.9502,.1,.9999,BETA_PDF,0.85,0.1;
-rho_l,.9542,.1,.9999,BETA_PDF,0.85,0.1;
-rho_i,.6705,.1,.99,BETA_PDF,0.85,0.1;
-phi_i,5.2083,1,15,NORMAL_PDF,4,1.5;
-sig_c,0.9817,0.25,3,NORMAL_PDF,1,0.375;
-hab,0.5612,0.3,0.95,BETA_PDF,0.7,0.1;
-xi_w,0.7661,0.3,0.9,BETA_PDF,0.75,0.05;
-sig_l,1.7526,0.5,5,NORMAL_PDF,2,0.75;
-xi_p,0.8684,0.3,0.95,BETA_PDF,0.75,0.05;
-xi_e,0.5724,0.1,0.95,BETA_PDF,0.5,0.15;
-gamma_w,0.6202,0.1,0.99,BETA_PDF,0.75,0.15;
-gamma_p,0.6638,0.1,0.99,BETA_PDF,0.75,0.15;
-czcap,0.2516,0.01,2,NORMAL_PDF,0.2,0.075;
-phi_y,1.3011,1.001,2,NORMAL_PDF,1.45,0.125;
-r_pie,1.4616,1.2,2,NORMAL_PDF,1.7,0.1;
-r_dpi,0.1144,0.01,0.5,NORMAL_PDF,0.3,0.1;
-rho,0.8865,0.5,0.99,BETA_PDF,0.8,0.10;
-r_y,0.0571,0.01,0.2,NORMAL_PDF,0.125,0.05;
-r_dy,0.2228,0.05,0.5,NORMAL_PDF,0.0625,0.05;
-end;
-
-varobs Y C I E PIE W R;
-
-//estimation(datafile=rawdata_euromodel_1,presample=40, first_obs=1, nobs=118, lik_init=2, mode_compute=1,mh_replic=0);
-estimation(datafile=rawdata_euromodel_1,presample=40, first_obs=1, nobs=118,mh_jscale=0.2,mh_replic=150000, mode_check); //
-
-
-//stoch_simul(periods=200,irf=20,simul_seed=3) Y C PIE R W R_K L Q I K ;
-
+//options_.usePartInfo=1;
+
+var MC E EF R_KF QF CF IF YF LF PIEF WF RF R_K Q C I Y L PIE W R EE_A PIE_BAR EE_B EE_G EE_L EE_I KF K one BIGTHETA;    
+
+varexo E_A E_B E_G E_L E_I ETA_R E_PIE_BAR ETA_Q ETA_P ETA_W  ;  
+ 
+parameters 
+xi_e lambda_w alpha czcap beta phi_i tau sig_c hab ccs cinvs phi_y gamma_w xi_w gamma_p xi_p sig_l r_dpi 
+r_pie r_dy r_y rho rho_a rho_pb rho_b rho_g rho_l rho_i LMP  ;
+
+
+
+alpha=.30;
+beta=.99;
+tau=0.025;
+ccs=0.6;
+cinvs=.22;  //% alpha*(tau+ctrend)/R_K   R_K=ctrend/beta-1+tau  
+lambda_w = 0.5;
+phi_i= 6.771;
+sig_c=   1.353; 
+hab=    0.573;    
+xi_w=   0.737;
+sig_l=    2.400;
+xi_p=   0.908;
+xi_e= 0.599;
+gamma_w=    0.763;
+gamma_p=    0.469;
+czcap=    0.169;
+phi_y=    1.408;
+r_pie=     1.684;
+r_dpi=    0.14;
+rho=      0.961;
+r_y=      0.099;
+r_dy=     0.159;
+rho_a=    0.823;
+rho_b=    0.855;
+rho_g=    0.949;
+rho_l=   0.889;
+rho_i=   0.927;
+rho_pb=  0.924;
+LMP = 0.0 ; //NEW.
+
+model(linear, use_dll); 
+          CF = (1/(1+hab))*(CF(1)+hab*CF(-1))-((1-hab)/((1+hab)*sig_c))*(RF-PIEF(1)-EE_B) ;
+	      0 =  alpha*R_KF+(1-alpha)*WF -EE_A ;
+          PIEF = 0*one;
+	      IF = (1/(1+beta))* ((  IF(-1) + beta*(IF(1)))+(1/phi_i)*QF)+0*ETA_Q+EE_I ;
+	      QF = -(RF-PIEF(1))+(1-beta*(1-tau))*((0+czcap)/czcap)*R_KF(1)+beta*(1-tau)*QF(1) +0*EE_I ;
+          KF =  (1-tau)*KF(-1)+tau*IF(-1) ;
+	      YF = (ccs*CF+cinvs*IF)+EE_G  ;
+
+	      YF = 1*phi_y*( alpha*KF+alpha*(1/czcap)*R_KF+(1-alpha)*LF+EE_A ) ;
+	      WF = (sig_c/(1-hab))*(CF-hab*CF(-1)) + sig_l*LF - EE_L ;
+	      LF = R_KF*((1+czcap)/czcap)-WF+KF ;
+          EF = EF(-1)+EF(1)-EF+(LF-EF)*((1-xi_e)*(1-xi_e*beta)/(xi_e));
+         
+	      C = (hab/(1+hab))*C(-1)+(1/(1+hab))*C(1)-((1-hab)/((1+hab)*sig_c))*(R-PIE(1)-EE_B) ;
+	      I = (1/(1+beta))* ((  I(-1) + beta*(I(1)))+(1/phi_i)*Q )+1*ETA_Q+1*EE_I ;
+	      Q = -(R-PIE(1))+(1-beta*(1-tau))*((0+czcap)/czcap)*R_K(1)+beta*(1-tau)*Q(1) +EE_I*0+0*ETA_Q ;
+	      K =  (1-tau)*K(-1)+tau*I(-1) ;
+	      Y = (ccs*C+cinvs*I)+ EE_G   ;
+	      Y = phi_y*( alpha*K+alpha*(1/czcap)*R_K+(1-alpha)*L ) +phi_y*EE_A  ;
+	      PIE = (1/(1+beta*gamma_p))*
+	            ( 
+	            (beta)*(PIE(1)) +(gamma_p)*(PIE(-1)) 
+	            +((1-xi_p)*(1-beta*xi_p)/(xi_p))*(MC)
+	            )  + ETA_P ; 
+	            
+	      MC = alpha*R_K+(1-alpha)*W -EE_A;
+	      W =  (1/(1+beta))*(beta*W(+1)+W(-1))
+                +(beta/(1+beta))*(PIE(+1))
+                -((1+beta*gamma_w)/(1+beta))*(PIE)
+                +(gamma_w/(1+beta))*(PIE(-1))
+                -(1/(1+beta))*(((1-beta*xi_w)*(1-xi_w))/(((1+(((1+lambda_w)*sig_l)/(lambda_w))))*xi_w))*(W-sig_l*L-(sig_c/(1-hab))*(C-hab*C(-1))+EE_L)
+                +ETA_W;
+	      L = R_K*((1+czcap)/czcap)-W+K ;
+
+//	      R = r_dpi*(PIE-PIE(-1))
+//              +(1-rho)*(r_pie*(PIE(-1)-PIE_BAR)+r_y*(Y-YF))
+//              +r_dy*(Y-YF-(Y(-1)-YF(-1)))
+//              +rho*(R(-1)-PIE_BAR)
+//              +PIE_BAR
+//              +ETA_R;
+
+
+	      R = 
+
+r_dpi*(PIE-PIE(-1))
+
+              +(1-rho)*(r_pie*(BIGTHETA)+r_y*(Y-YF))
+              +r_dy*(Y-YF-(Y(-1)-YF(-1)))
+              +rho*(R(-1)-PIE_BAR)
+              +PIE_BAR
+              +ETA_R;
+
+
+          E = E(-1)+E(1)-E+(L-E)*((1-xi_e)*(1-xi_e*beta)/(xi_e));
+          
+          
+          EE_A = (rho_a)*EE_A(-1)  + E_A;
+	      PIE_BAR = rho_pb*PIE_BAR(-1)+ E_PIE_BAR ;
+	      EE_B = rho_b*EE_B(-1) + E_B ;
+	      EE_G = rho_g*EE_G(-1) + E_G ;
+	      EE_L = rho_l*EE_L(-1) + E_L ;
+	      EE_I = rho_i*EE_I(-1) + E_I ;
+	      one = 0*one(-1) ;
+
+		LMP*BIGTHETA(1) = BIGTHETA - (PIE(-1) - PIE_BAR) ; 
+
+end; 
+
+ 
+shocks;
+var E_A; stderr 0.598;
+var E_B; stderr 0.336;
+var E_G; stderr 0.325;
+var E_I; stderr 0.085;
+var E_L; stderr 3.520;
+var ETA_P; stderr 0.160;
+var ETA_W; stderr 0.289;
+var ETA_R; stderr 0.081;
+var ETA_Q; stderr 0.604;
+var E_PIE_BAR; stderr 0.017;
+end;
+
+//stoch_simul(irf=20) Y C PIE R W R_K L Q I K ;
+
+// stoch_simul generates what kind of standard errors for the shocks ?
+
+//steady;
+//check;
+//stoch_simul(periods=200,irf=20,simul_seed=3) Y C PIE MC R W R_K E L I ;
+
+//datatomfile('ddd',[]);
+
+// new syntax 
+
+estimated_params;
+// PARAM NAME, INITVAL, LB, UB, PRIOR_SHAPE, PRIOR_P1, PRIOR_P2, PRIOR_P3, PRIOR_P4, JSCALE
+// PRIOR_SHAPE: BETA_PDF, GAMMA_PDF, NORMAL_PDF, INV_GAMMA_PDF
+stderr E_A,0.543,0.01,4,INV_GAMMA_PDF,0.4,2;
+stderr E_PIE_BAR,0.072,0.001,4,INV_GAMMA_PDF,0.02,10;
+stderr E_B,0.2694,0.01,4,INV_GAMMA_PDF,0.2,2;
+stderr E_G,0.3052,0.01,4,INV_GAMMA_PDF,0.3,2;
+stderr E_L,1.4575,0.1,6,INV_GAMMA_PDF,1,2;
+stderr E_I,0.1318,0.01,4,INV_GAMMA_PDF,0.1,2;
+stderr ETA_R,0.1363,0.01,4,INV_GAMMA_PDF,0.1,2;
+stderr ETA_Q,0.4842,0.01,4,INV_GAMMA_PDF,0.4,2;
+stderr ETA_P,0.1731,0.01,4,INV_GAMMA_PDF,0.15,2;
+stderr ETA_W,0.2462,0.1,4,INV_GAMMA_PDF,0.25,2;
+rho_a,.9722,.1,.9999,BETA_PDF,0.85,0.1;
+rho_pb,.85,.1,.999,BETA_PDF,0.85,0.1;
+rho_b,.7647,.1,.99,BETA_PDF,0.85,0.1;
+rho_g,.9502,.1,.9999,BETA_PDF,0.85,0.1;
+rho_l,.9542,.1,.9999,BETA_PDF,0.85,0.1;
+rho_i,.6705,.1,.99,BETA_PDF,0.85,0.1;
+phi_i,5.2083,1,15,NORMAL_PDF,4,1.5;
+sig_c,0.9817,0.25,3,NORMAL_PDF,1,0.375;
+hab,0.5612,0.3,0.95,BETA_PDF,0.7,0.1;
+xi_w,0.7661,0.3,0.9,BETA_PDF,0.75,0.05;
+sig_l,1.7526,0.5,5,NORMAL_PDF,2,0.75;
+xi_p,0.8684,0.3,0.95,BETA_PDF,0.75,0.05;
+xi_e,0.5724,0.1,0.95,BETA_PDF,0.5,0.15;
+gamma_w,0.6202,0.1,0.99,BETA_PDF,0.75,0.15;
+gamma_p,0.6638,0.1,0.99,BETA_PDF,0.75,0.15;
+czcap,0.2516,0.01,2,NORMAL_PDF,0.2,0.075;
+phi_y,1.3011,1.001,2,NORMAL_PDF,1.45,0.125;
+r_pie,1.4616,1.2,2,NORMAL_PDF,1.7,0.1;
+r_dpi,0.1144,0.01,0.5,NORMAL_PDF,0.3,0.1;
+rho,0.8865,0.5,0.99,BETA_PDF,0.8,0.10;
+r_y,0.0571,0.01,0.2,NORMAL_PDF,0.125,0.05;
+r_dy,0.2228,0.05,0.5,NORMAL_PDF,0.0625,0.05;
+end;
+
+varobs Y C I E PIE W R;
+
+//estimation(datafile=rawdata_euromodel_1,presample=40, first_obs=1, nobs=118, lik_init=2, mode_compute=1,mh_replic=0);
+estimation(datafile=rawdata_euromodel_1,presample=40, first_obs=1, nobs=118,mh_jscale=0.2,mh_replic=150000, mode_check); //
+
+
+//stoch_simul(periods=200,irf=20,simul_seed=3) Y C PIE R W R_K L Q I K ;
+
diff --git a/mex/sources/k_order_perturbation/tests/fs2000k.mod b/mex/sources/k_order_perturbation/tests/fs2000k.mod
index 731a946c7a..850b1f9382 100644
--- a/mex/sources/k_order_perturbation/tests/fs2000k.mod
+++ b/mex/sources/k_order_perturbation/tests/fs2000k.mod
@@ -1,119 +1,119 @@
-// This file replicates the estimation of the CIA model from 
-// Frank Schorfheide (2000) "Loss function-based evaluation of DSGE models" 
-// Journal of  Applied Econometrics, 15, 645-670.
-// the data are the ones provided on Schorfheide's web site with the programs.
-// http://www.econ.upenn.edu/~schorf/programs/dsgesel.ZIP
-// You need to have fsdat.m in the same directory as this file.
-// This file replicates: 
-// -the posterior mode as computed by Frank's Gauss programs
-// -the parameter mean posterior estimates reported in the paper
-// -the model probability (harmonic mean) reported in the paper
-// This file was tested with dyn_mat_test_0218.zip
-// the smooth shocks are probably stil buggy
-//
-// The equations are taken from J. Nason and T. Cogley (1994) 
-// "Testing the implications of long-run neutrality for monetary business
-// cycle models" Journal of Applied Econometrics, 9, S37-S70.
-// Note that there is an initial minus sign missing in equation (A1), p. S63.
-//
-// Michel Juillard, February 2004
-// Modified for testing k_order_perturbation by GP, Jan-Feb 09
-
-options_.usePartInfo=0;
-options_.use_k_order=0;
-
-//var m m_1 P P_1 c e W R k d n l gy_obs gp_obs Y_obs P_obs y dA P2 c2;
-var m m_1 P P_1 c e W R k d n l gy_obs gp_obs y dA P2 c2;
-varexo e_a e_m;
-
-parameters alp bet gam mst rho psi del;
-
-alp = 0.33;
-bet = 0.99;
-gam = 0.003;
-mst = 1.011;
-rho = 0.7;
-psi = 0.787;
-del = 0.02;
-
-model (use_dll);
-dA = exp(gam+e_a);
-log(m) = (1-rho)*log(mst) + rho*log(m_1(-1))+e_m;
--P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c2(+1)*P2(+1)*m(+1))=0;
-W = l/n;
--(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
-R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
-1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
-c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
-P*c = m;
-m-1+d = l;
-e = exp(e_a);
-y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
-gy_obs = dA*y/y(-1);
-gp_obs = (P/P_1(-1))*m_1(-1)/dA;
-//Y_obs/Y_obs(-1) = gy_obs;
-//P_obs/P_obs(-1) = gp_obs;
-P2 = P(+1);
-c2 = c(+1);
-m_1 = m;
-P_1 = P;
-end;
-
-initval;
-m = mst;
-m_1=mst;
-P = 2.25;
-P_1 = 2.25;
-c = 0.45;
-e = 1;
-W = 4;
-R = 1.02;
-k = 6;
-d = 0.85;
-n = 0.19;
-l = 0.86;
-y = 0.6;
-gy_obs = exp(gam);
-gp_obs = exp(-gam); 
-dA = exp(gam);
-  P2=P;
-  c2=c;
-end;
-
-shocks;
-var e_a; stderr 0.014;
-var e_m; stderr 0.005;
-end;
-
-//unit_root_vars P_obs Y_obs;
-
-steady(solve_algo = 2);
-
-check;
-
-estimated_params;
-alp, beta_pdf, 0.356, 0.02; 
-bet, beta_pdf, 0.993, 0.002;
-gam, normal_pdf, 0.0085, 0.003;
-mst, normal_pdf, 1.0002, 0.007;
-rho, beta_pdf, 0.129, 0.223;
-psi, beta_pdf, 0.65, 0.05;
-del, beta_pdf, 0.01, 0.005;
-stderr e_a, inv_gamma_pdf, 0.035449, inf;
-stderr e_m, inv_gamma_pdf, 0.008862, inf;
-end;
-
-//varobs P_obs Y_obs;
-varobs gp_obs gy_obs;
-
-steady(solve_algo = 2);
-
-//observation_trends;
-//P_obs (log(mst)-gam);
-//Y_obs (gam);
-//end;
-
-//options_.useAIM = 1;
-estimation(datafile=fsdat,nobs=192,loglinear,mh_replic=2000,
-	mode_compute=4,mh_nblocks=2,mh_drop=0.45,mh_jscale=0.65);
-
+// This file replicates the estimation of the CIA model from 
+// Frank Schorfheide (2000) "Loss function-based evaluation of DSGE models" 
+// Journal of  Applied Econometrics, 15, 645-670.
+// the data are the ones provided on Schorfheide's web site with the programs.
+// http://www.econ.upenn.edu/~schorf/programs/dsgesel.ZIP
+// You need to have fsdat.m in the same directory as this file.
+// This file replicates: 
+// -the posterior mode as computed by Frank's Gauss programs
+// -the parameter mean posterior estimates reported in the paper
+// -the model probability (harmonic mean) reported in the paper
+// This file was tested with dyn_mat_test_0218.zip
+// the smooth shocks are probably stil buggy
+//
+// The equations are taken from J. Nason and T. Cogley (1994) 
+// "Testing the implications of long-run neutrality for monetary business
+// cycle models" Journal of Applied Econometrics, 9, S37-S70.
+// Note that there is an initial minus sign missing in equation (A1), p. S63.
+//
+// Michel Juillard, February 2004
+// Modified for testing k_order_perturbation by GP, Jan-Feb 09
+
+options_.usePartInfo=0;
+options_.use_k_order=0;
+
+//var m m_1 P P_1 c e W R k d n l gy_obs gp_obs Y_obs P_obs y dA P2 c2;
+var m m_1 P P_1 c e W R k d n l gy_obs gp_obs y dA P2 c2;
+varexo e_a e_m;
+
+parameters alp bet gam mst rho psi del;
+
+alp = 0.33;
+bet = 0.99;
+gam = 0.003;
+mst = 1.011;
+rho = 0.7;
+psi = 0.787;
+del = 0.02;
+
+model (use_dll);
+dA = exp(gam+e_a);
+log(m) = (1-rho)*log(mst) + rho*log(m_1(-1))+e_m;
+-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c2(+1)*P2(+1)*m(+1))=0;
+W = l/n;
+-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
+R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
+1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
+c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
+P*c = m;
+m-1+d = l;
+e = exp(e_a);
+y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
+gy_obs = dA*y/y(-1);
+gp_obs = (P/P_1(-1))*m_1(-1)/dA;
+//Y_obs/Y_obs(-1) = gy_obs;
+//P_obs/P_obs(-1) = gp_obs;
+P2 = P(+1);
+c2 = c(+1);
+m_1 = m;
+P_1 = P;
+end;
+
+initval;
+m = mst;
+m_1=mst;
+P = 2.25;
+P_1 = 2.25;
+c = 0.45;
+e = 1;
+W = 4;
+R = 1.02;
+k = 6;
+d = 0.85;
+n = 0.19;
+l = 0.86;
+y = 0.6;
+gy_obs = exp(gam);
+gp_obs = exp(-gam); 
+dA = exp(gam);
+  P2=P;
+  c2=c;
+end;
+
+shocks;
+var e_a; stderr 0.014;
+var e_m; stderr 0.005;
+end;
+
+//unit_root_vars P_obs Y_obs;
+
+steady(solve_algo = 2);
+
+check;
+
+estimated_params;
+alp, beta_pdf, 0.356, 0.02; 
+bet, beta_pdf, 0.993, 0.002;
+gam, normal_pdf, 0.0085, 0.003;
+mst, normal_pdf, 1.0002, 0.007;
+rho, beta_pdf, 0.129, 0.223;
+psi, beta_pdf, 0.65, 0.05;
+del, beta_pdf, 0.01, 0.005;
+stderr e_a, inv_gamma_pdf, 0.035449, inf;
+stderr e_m, inv_gamma_pdf, 0.008862, inf;
+end;
+
+//varobs P_obs Y_obs;
+varobs gp_obs gy_obs;
+
+steady(solve_algo = 2);
+
+//observation_trends;
+//P_obs (log(mst)-gam);
+//Y_obs (gam);
+//end;
+
+//options_.useAIM = 1;
+estimation(datafile=fsdat,nobs=192,loglinear,mh_replic=2000,
+	mode_compute=4,mh_nblocks=2,mh_drop=0.45,mh_jscale=0.65);
+
diff --git a/tests/AIM/data_ca1.m b/tests/AIM/data_ca1.m
index b0b4f05461..c28fae1a28 100644
--- a/tests/AIM/data_ca1.m
+++ b/tests/AIM/data_ca1.m
@@ -1,100 +1,100 @@
-data = [0.928467646476  11.8716889412   20  0.418037507392  0.227382377518 ...
--0.705994063083 11.7522582094   21.25   1.09254424511   -1.29488274994 ...
--0.511895351926 9.68144025625   17.25   -1.66150408407  0.331508393098 ...
--0.990955971267 10.0890781236   17  1.43016275252   -2.43589670141 ...
--0.981233061806 12.1094840679   18.25   2.91293288733   -0.790246576864 ...
--0.882182844512 8.54559460406   15  0.419579139481  0.358729719566 ...
--0.930893002836 6.19238374422   12.5    -1.48847457959  0.739779938797 ...
-1.53158206947   2.76544271886   11.5    -0.336216769682 0.455559918769 ...
-2.2659052834    5.47418162513   11  0.306436789767  -0.0707985731221 ...
-1.05419803797   6.35698426189   11  0.140700250477  0.620401487202 ...
-1.20161076793   3.4253301593    11  0.461296492351  0.14354323987 ...
-1.73934077971   4.70926070322   11.5    1.35798282982   0.38564694435 ...
-1.71735262584   3.54232079749   12.5    2.9097529155    -0.804308583301 ...
-0.426343657844  3.32719108897   13  1.64214862652   -1.18214664701 ...
-1.67751812324   2.93444727338   11.25   0.344434910651  -1.6529373719 ...
-1.37013301099   4.72303361923   11.75   2.61511526582   0.327684243041 ...
-0.281231073781  4.4893853071    10.5    1.17043449257   1.12855106649 ...
-1.53638992834   3.7325309699    10.25   -0.683947046728 0.11943538737 ...
-1.68081431462   3.34729969129   10  1.41159342106   -1.59065680853 ...
--0.343321601133 5.05563513564   12  1.75117366498   -2.40127764642 ...
-0.873415608666  3.2779996255    10.25   -1.39895866711  0.0971444398216 ...
-0.26399696544   4.78229419828   9.75    0.0914692438124 0.299310457612 ...
--0.562233624818 3.88598638237   9.75    -0.0505384765105    0.332826708151 ...
-2.15161914936   3.84859710132   8.75    -3.44811080489  0.789138678784 ...
-1.2345093726    5.62225030942   9.5 -0.366945407434 2.32974981198 ...
-1.62554967459   4.24667132831   10  -0.800958371402 0.0293183770935 ...
-1.33035402527   2.75248979249   9.75    -0.855723113225 0.852493939813 ...
-1.52078814077   3.53415985826   9.75    -3.37963469203  -1.05133958119 ...
-1.16704983697   4.92754079464   10.75   -3.0142303324   0.459907431978 ...
-0.277213572101  4.55532133037   11.75   -0.851995599415 2.03242034852 ...
-0.842215068977  3.11164509647   12.25   -1.08290421696  0.014323281961 ...
-1.05325028606   4.92882647578   13.5    -1.1953883867   0.706764750654 ...
-0.453051253568  6.82998950103   13.5    0.111803656462  0.088462593153 ...
-0.199885995525  5.82643354662   13.5    -0.920501518421 -0.26504958666 ...
-0.137907999624  2.66076369132   13.5    -1.17122929812  -0.995642430514 ...
-0.721949686709  5.70497876823   14.25   1.19378169018   -1.10644839651 ...
--0.418465249225 3.75861110232   14.75   -1.03131674824  0.188507675831 ...
--0.644028342116 4.15104788154   13.75   -1.48911756546  0.204560913792 ...
--0.848213852668 5.65580324027   12.75   0.677011703877  -0.849628054542 ...
--1.51954076928  11.4866911266   11.25   -0.446024680774 -0.456342350765 ...
-0.265275055215  2.85472749592   9.75    -0.598778202436 -0.907311640831 ...
-0.356162529063  2.29614015658   9.5 -0.46820788432  -1.22130883441 ...
-0.368308864363  -0.539083504685 8   -0.781333991956 0.374007246518 ...
--0.145751412732 1.61507621789   8.25    3.68291932628   1.32438399845 ...
-0.285457283664  2.14334055993   7   1.42819405379   -0.00818660844123 ...
-0.372390129412  1.60000213334   6.25    0.626106424052  -0.10136772765 ...
-0.382720203063  1.72614243263   7.25    4.89631941021   -1.10060711916 ...
-0.737957515573  2.90430582851   6   -0.0422721010314    0.4178952497 ...
-0.649532581668  0.657135682543  6   0.692066153971  0.422299120276 ...
-0.627159201987  1.70352689913   5.75    2.62066711305   -1.29237304034 ...
-0.905441299817  1.95663197267   5.5 1.5949697565    -0.27115830703 ...
-1.49322577898   -2.08741765309  6.25    1.23027694802   0.418336889527 ...
-1.48750731567   -1.57274121871  8   3.01660550994   -0.893958254365 ...
-1.39783858087   2.22623066426   7   -0.80842319214  1.47625453886 ...
-0.89274836317   1.30378081742   8   -0.249485058661 0.159871204185 ...
-0.920652246088  4.1437741965    9.75    2.8204453623    0.178149239655 ...
--0.00264276644799   3.07989972052   8.75    -2.56342461535  2.105998353 ...
-0.0198190461681 0.766283759256  8   -1.15838865989  1.56888883418 ...
-0.440050515311  0.127570085801  7.5 0.0400753569995 0.028914333532 ...
-0.129536637901  1.78174141526   6.75    0.959943962785  0.307781224401 ...
-0.398549827172  3.03606770667   6.5 -0.340209794742 0.100979469478 ...
-1.17174775425   0.629625188037  5.75    0.403003686814  0.902394579377 ...
-0.991163981251  2.50862910684   4.75    -1.44963996982  1.16150986945 ...
-0.967603566096  2.12003739013   4.75    0.610846030775  -0.889994896068 ...
-1.14689383604   1.24185011459   4.75    2.01098091308   -1.73846431001 ...
-1.32593824054   0.990713820685  4.75    -0.0955142989332    -0.0369257308362 ...
-0.861135002644  -0.24744943605  6   1.72793107135   -0.691506789639 ...
-1.26870850151   2.09844764887   6.5 1.50720217572   -1.31399187077 ...
-0.260364987715  1.10650139716   6.5 1.13659047496   0.0720441664643 ...
-1.09731242214   0.490796381346  7.25    4.59123894147   -2.14073070763 ...
-1.63792841781   0.612652594286  6.75    1.79604605035   -0.644363995357 ...
-1.48465576034   0.978295808687  6.75    -2.00753620902  1.39437534964 ...
-1.0987608663    4.25212569087   6.25    -2.58901196498  2.56054320803 ...
-1.42592178132   2.76984518311   6.25    0.888195752358  1.03114549274 ...
-1.52958239462   1.31795955491   6.5 -0.902907564082 -0.0952198893776 ...
-1.0170168994    2.14733589918   7   -1.3054866978   2.68803738466 ...
-0.723253652257  3.43552889347   7.5 1.8213700853    0.592593586195 ...
-1.24720806008   3.87383806577   7.5 0.0522300654168 0.988871238698 ...
-0.482531471239  2.67793287032   7.5 2.9693944293    -0.108591166081 ...
-0.154056100439  0.927269031704  6.75    0.119222057561  3.30489209451 ...
-0.0694865769274 6.65916526788   6.25    0.889014476084  -2.83976849035 ...
--0.121267434867 0.341442615696  5.25    0.323053239216  -3.49289229012 ...
-0.726473690375  -3.5423730964   4   2.19149290449   -3.20855054004 ...
-1.39271709108   2.63121085718   3.75    0.88406577736   0.75622580197 ...
-1.07502077727   5.88578836799   4.25    -2.55088273352  2.89018116374 ...
-0.759049251607  4.24703604223   4.5 0.575687665685  -0.388292506167 ...
-]; 
- 
-data = reshape(data,5,86)'; 
-y_obs = data(:,1); 
-pie_obs = data(:,2); 
-R_obs = data(:,3); 
-de = data(:,4); 
-dq = data(:,5); 
- 
-%Country: Canada 
-%Sample Range: 1981:2 to 2002:3 
-%Observations: 86 
-%Variables: Real GDP Growth [%], Inflation [annualized %], Nom Rate [%], 
-%           Exchange Rate Change [%], Terms of Trade Change [%] 
+data = [0.928467646476  11.8716889412   20  0.418037507392  0.227382377518 ...
+-0.705994063083 11.7522582094   21.25   1.09254424511   -1.29488274994 ...
+-0.511895351926 9.68144025625   17.25   -1.66150408407  0.331508393098 ...
+-0.990955971267 10.0890781236   17  1.43016275252   -2.43589670141 ...
+-0.981233061806 12.1094840679   18.25   2.91293288733   -0.790246576864 ...
+-0.882182844512 8.54559460406   15  0.419579139481  0.358729719566 ...
+-0.930893002836 6.19238374422   12.5    -1.48847457959  0.739779938797 ...
+1.53158206947   2.76544271886   11.5    -0.336216769682 0.455559918769 ...
+2.2659052834    5.47418162513   11  0.306436789767  -0.0707985731221 ...
+1.05419803797   6.35698426189   11  0.140700250477  0.620401487202 ...
+1.20161076793   3.4253301593    11  0.461296492351  0.14354323987 ...
+1.73934077971   4.70926070322   11.5    1.35798282982   0.38564694435 ...
+1.71735262584   3.54232079749   12.5    2.9097529155    -0.804308583301 ...
+0.426343657844  3.32719108897   13  1.64214862652   -1.18214664701 ...
+1.67751812324   2.93444727338   11.25   0.344434910651  -1.6529373719 ...
+1.37013301099   4.72303361923   11.75   2.61511526582   0.327684243041 ...
+0.281231073781  4.4893853071    10.5    1.17043449257   1.12855106649 ...
+1.53638992834   3.7325309699    10.25   -0.683947046728 0.11943538737 ...
+1.68081431462   3.34729969129   10  1.41159342106   -1.59065680853 ...
+-0.343321601133 5.05563513564   12  1.75117366498   -2.40127764642 ...
+0.873415608666  3.2779996255    10.25   -1.39895866711  0.0971444398216 ...
+0.26399696544   4.78229419828   9.75    0.0914692438124 0.299310457612 ...
+-0.562233624818 3.88598638237   9.75    -0.0505384765105    0.332826708151 ...
+2.15161914936   3.84859710132   8.75    -3.44811080489  0.789138678784 ...
+1.2345093726    5.62225030942   9.5 -0.366945407434 2.32974981198 ...
+1.62554967459   4.24667132831   10  -0.800958371402 0.0293183770935 ...
+1.33035402527   2.75248979249   9.75    -0.855723113225 0.852493939813 ...
+1.52078814077   3.53415985826   9.75    -3.37963469203  -1.05133958119 ...
+1.16704983697   4.92754079464   10.75   -3.0142303324   0.459907431978 ...
+0.277213572101  4.55532133037   11.75   -0.851995599415 2.03242034852 ...
+0.842215068977  3.11164509647   12.25   -1.08290421696  0.014323281961 ...
+1.05325028606   4.92882647578   13.5    -1.1953883867   0.706764750654 ...
+0.453051253568  6.82998950103   13.5    0.111803656462  0.088462593153 ...
+0.199885995525  5.82643354662   13.5    -0.920501518421 -0.26504958666 ...
+0.137907999624  2.66076369132   13.5    -1.17122929812  -0.995642430514 ...
+0.721949686709  5.70497876823   14.25   1.19378169018   -1.10644839651 ...
+-0.418465249225 3.75861110232   14.75   -1.03131674824  0.188507675831 ...
+-0.644028342116 4.15104788154   13.75   -1.48911756546  0.204560913792 ...
+-0.848213852668 5.65580324027   12.75   0.677011703877  -0.849628054542 ...
+-1.51954076928  11.4866911266   11.25   -0.446024680774 -0.456342350765 ...
+0.265275055215  2.85472749592   9.75    -0.598778202436 -0.907311640831 ...
+0.356162529063  2.29614015658   9.5 -0.46820788432  -1.22130883441 ...
+0.368308864363  -0.539083504685 8   -0.781333991956 0.374007246518 ...
+-0.145751412732 1.61507621789   8.25    3.68291932628   1.32438399845 ...
+0.285457283664  2.14334055993   7   1.42819405379   -0.00818660844123 ...
+0.372390129412  1.60000213334   6.25    0.626106424052  -0.10136772765 ...
+0.382720203063  1.72614243263   7.25    4.89631941021   -1.10060711916 ...
+0.737957515573  2.90430582851   6   -0.0422721010314    0.4178952497 ...
+0.649532581668  0.657135682543  6   0.692066153971  0.422299120276 ...
+0.627159201987  1.70352689913   5.75    2.62066711305   -1.29237304034 ...
+0.905441299817  1.95663197267   5.5 1.5949697565    -0.27115830703 ...
+1.49322577898   -2.08741765309  6.25    1.23027694802   0.418336889527 ...
+1.48750731567   -1.57274121871  8   3.01660550994   -0.893958254365 ...
+1.39783858087   2.22623066426   7   -0.80842319214  1.47625453886 ...
+0.89274836317   1.30378081742   8   -0.249485058661 0.159871204185 ...
+0.920652246088  4.1437741965    9.75    2.8204453623    0.178149239655 ...
+-0.00264276644799   3.07989972052   8.75    -2.56342461535  2.105998353 ...
+0.0198190461681 0.766283759256  8   -1.15838865989  1.56888883418 ...
+0.440050515311  0.127570085801  7.5 0.0400753569995 0.028914333532 ...
+0.129536637901  1.78174141526   6.75    0.959943962785  0.307781224401 ...
+0.398549827172  3.03606770667   6.5 -0.340209794742 0.100979469478 ...
+1.17174775425   0.629625188037  5.75    0.403003686814  0.902394579377 ...
+0.991163981251  2.50862910684   4.75    -1.44963996982  1.16150986945 ...
+0.967603566096  2.12003739013   4.75    0.610846030775  -0.889994896068 ...
+1.14689383604   1.24185011459   4.75    2.01098091308   -1.73846431001 ...
+1.32593824054   0.990713820685  4.75    -0.0955142989332    -0.0369257308362 ...
+0.861135002644  -0.24744943605  6   1.72793107135   -0.691506789639 ...
+1.26870850151   2.09844764887   6.5 1.50720217572   -1.31399187077 ...
+0.260364987715  1.10650139716   6.5 1.13659047496   0.0720441664643 ...
+1.09731242214   0.490796381346  7.25    4.59123894147   -2.14073070763 ...
+1.63792841781   0.612652594286  6.75    1.79604605035   -0.644363995357 ...
+1.48465576034   0.978295808687  6.75    -2.00753620902  1.39437534964 ...
+1.0987608663    4.25212569087   6.25    -2.58901196498  2.56054320803 ...
+1.42592178132   2.76984518311   6.25    0.888195752358  1.03114549274 ...
+1.52958239462   1.31795955491   6.5 -0.902907564082 -0.0952198893776 ...
+1.0170168994    2.14733589918   7   -1.3054866978   2.68803738466 ...
+0.723253652257  3.43552889347   7.5 1.8213700853    0.592593586195 ...
+1.24720806008   3.87383806577   7.5 0.0522300654168 0.988871238698 ...
+0.482531471239  2.67793287032   7.5 2.9693944293    -0.108591166081 ...
+0.154056100439  0.927269031704  6.75    0.119222057561  3.30489209451 ...
+0.0694865769274 6.65916526788   6.25    0.889014476084  -2.83976849035 ...
+-0.121267434867 0.341442615696  5.25    0.323053239216  -3.49289229012 ...
+0.726473690375  -3.5423730964   4   2.19149290449   -3.20855054004 ...
+1.39271709108   2.63121085718   3.75    0.88406577736   0.75622580197 ...
+1.07502077727   5.88578836799   4.25    -2.55088273352  2.89018116374 ...
+0.759049251607  4.24703604223   4.5 0.575687665685  -0.388292506167 ...
+]; 
+ 
+data = reshape(data,5,86)'; 
+y_obs = data(:,1); 
+pie_obs = data(:,2); 
+R_obs = data(:,3); 
+de = data(:,4); 
+dq = data(:,5); 
+ 
+%Country: Canada 
+%Sample Range: 1981:2 to 2002:3 
+%Observations: 86 
+%Variables: Real GDP Growth [%], Inflation [annualized %], Nom Rate [%], 
+%           Exchange Rate Change [%], Terms of Trade Change [%] 
diff --git a/tests/AIM/fs2000_b1L1L_AIM_steadystate.m b/tests/AIM/fs2000_b1L1L_AIM_steadystate.m
index 3d427d7d10..eea49707dd 100644
--- a/tests/AIM/fs2000_b1L1L_AIM_steadystate.m
+++ b/tests/AIM/fs2000_b1L1L_AIM_steadystate.m
@@ -1,65 +1,65 @@
-% computes the steady state of fs2000 analyticaly
-% largely inspired by the program of F. Schorfheide
-function [ys,check] = fs2000k_steadystate(ys,exe)
-  global M_
-  
-  alp = M_.params(1); 
-  bet = M_.params(2); 
-  gam = M_.params(3); 
-  mst = M_.params(4); 
-  rho = M_.params(5); 
-  psi = M_.params(6); 
-  del = M_.params(7); 
-
-  check = 0;
-  
-  dA = exp(gam);
-  gst = 1/dA;
-  m = mst;
-  
-  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
-  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
-  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
-  n  = xist/(nust+xist);
-  P  = xist + nust;
-  k  = khst*n;
-
-  l  = psi*mst*n/( (1-psi)*(1-n) );
-  c  = mst/P;
-  d  = l - mst + 1;
-  y  = k^alp*n^(1-alp)*gst^alp;
-  R  = mst/bet;
-  W  = l/n;
-  ist  = y-c;
-  q  = 1 - d;
-
-  e = 1;
-  
-  gp_obs = m/dA;
-  gy_obs = dA;
-  
-  P_obs = 1;
-  Y_obs = 1;
-  
-  P2=P;
-  c2=c;
-  
-  ys =[
-    m     
-    P     
-    c     
-    e     
-    W     
-    R     
-    k     
-    d     
-    n     
-    l     
-    gy_obs
-    gp_obs
-    Y_obs 
-    P_obs 
-    y     
-    dA
-    P2
+% computes the steady state of fs2000 analyticaly
+% largely inspired by the program of F. Schorfheide
+function [ys,check] = fs2000k_steadystate(ys,exe)
+  global M_
+  
+  alp = M_.params(1); 
+  bet = M_.params(2); 
+  gam = M_.params(3); 
+  mst = M_.params(4); 
+  rho = M_.params(5); 
+  psi = M_.params(6); 
+  del = M_.params(7); 
+
+  check = 0;
+  
+  dA = exp(gam);
+  gst = 1/dA;
+  m = mst;
+  
+  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
+  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
+  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
+  n  = xist/(nust+xist);
+  P  = xist + nust;
+  k  = khst*n;
+
+  l  = psi*mst*n/( (1-psi)*(1-n) );
+  c  = mst/P;
+  d  = l - mst + 1;
+  y  = k^alp*n^(1-alp)*gst^alp;
+  R  = mst/bet;
+  W  = l/n;
+  ist  = y-c;
+  q  = 1 - d;
+
+  e = 1;
+  
+  gp_obs = m/dA;
+  gy_obs = dA;
+  
+  P_obs = 1;
+  Y_obs = 1;
+  
+  P2=P;
+  c2=c;
+  
+  ys =[
+    m     
+    P     
+    c     
+    e     
+    W     
+    R     
+    k     
+    d     
+    n     
+    l     
+    gy_obs
+    gp_obs
+    Y_obs 
+    P_obs 
+    y     
+    dA
+    P2
     c2  ];
\ No newline at end of file
diff --git a/tests/AIM/fs2000_b1L1L_steadystate.m b/tests/AIM/fs2000_b1L1L_steadystate.m
index 3d427d7d10..eea49707dd 100644
--- a/tests/AIM/fs2000_b1L1L_steadystate.m
+++ b/tests/AIM/fs2000_b1L1L_steadystate.m
@@ -1,65 +1,65 @@
-% computes the steady state of fs2000 analyticaly
-% largely inspired by the program of F. Schorfheide
-function [ys,check] = fs2000k_steadystate(ys,exe)
-  global M_
-  
-  alp = M_.params(1); 
-  bet = M_.params(2); 
-  gam = M_.params(3); 
-  mst = M_.params(4); 
-  rho = M_.params(5); 
-  psi = M_.params(6); 
-  del = M_.params(7); 
-
-  check = 0;
-  
-  dA = exp(gam);
-  gst = 1/dA;
-  m = mst;
-  
-  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
-  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
-  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
-  n  = xist/(nust+xist);
-  P  = xist + nust;
-  k  = khst*n;
-
-  l  = psi*mst*n/( (1-psi)*(1-n) );
-  c  = mst/P;
-  d  = l - mst + 1;
-  y  = k^alp*n^(1-alp)*gst^alp;
-  R  = mst/bet;
-  W  = l/n;
-  ist  = y-c;
-  q  = 1 - d;
-
-  e = 1;
-  
-  gp_obs = m/dA;
-  gy_obs = dA;
-  
-  P_obs = 1;
-  Y_obs = 1;
-  
-  P2=P;
-  c2=c;
-  
-  ys =[
-    m     
-    P     
-    c     
-    e     
-    W     
-    R     
-    k     
-    d     
-    n     
-    l     
-    gy_obs
-    gp_obs
-    Y_obs 
-    P_obs 
-    y     
-    dA
-    P2
+% computes the steady state of fs2000 analyticaly
+% largely inspired by the program of F. Schorfheide
+function [ys,check] = fs2000k_steadystate(ys,exe)
+  global M_
+  
+  alp = M_.params(1); 
+  bet = M_.params(2); 
+  gam = M_.params(3); 
+  mst = M_.params(4); 
+  rho = M_.params(5); 
+  psi = M_.params(6); 
+  del = M_.params(7); 
+
+  check = 0;
+  
+  dA = exp(gam);
+  gst = 1/dA;
+  m = mst;
+  
+  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
+  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
+  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
+  n  = xist/(nust+xist);
+  P  = xist + nust;
+  k  = khst*n;
+
+  l  = psi*mst*n/( (1-psi)*(1-n) );
+  c  = mst/P;
+  d  = l - mst + 1;
+  y  = k^alp*n^(1-alp)*gst^alp;
+  R  = mst/bet;
+  W  = l/n;
+  ist  = y-c;
+  q  = 1 - d;
+
+  e = 1;
+  
+  gp_obs = m/dA;
+  gy_obs = dA;
+  
+  P_obs = 1;
+  Y_obs = 1;
+  
+  P2=P;
+  c2=c;
+  
+  ys =[
+    m     
+    P     
+    c     
+    e     
+    W     
+    R     
+    k     
+    d     
+    n     
+    l     
+    gy_obs
+    gp_obs
+    Y_obs 
+    P_obs 
+    y     
+    dA
+    P2
     c2  ];
\ No newline at end of file
diff --git a/tests/AIM/fsdat.m b/tests/AIM/fsdat.m
index 5a0e3658d4..aba209b908 100644
--- a/tests/AIM/fsdat.m
+++ b/tests/AIM/fsdat.m
@@ -1,210 +1,210 @@
-data_q = [
-18.02 1474.5 150.2
-17.94 1538.2 150.9
-18.01 1584.5 151.4
-18.42 1644.1 152
-18.73 1678.6 152.7
-19.46 1693.1 153.3
-19.55 1724   153.9
-19.56 1758.2 154.7
-19.79 1760.6 155.4
-19.77 1779.2 156
-19.82 1778.8 156.6
-20.03 1790.9 157.3
-20.12 1846   158
-20.1  1882.6 158.6
-20.14 1897.3 159.2
-20.22 1887.4 160
-20.27 1858.2 160.7
-20.34 1849.9 161.4
-20.39 1848.5 162
-20.42 1868.9 162.8
-20.47 1905.6 163.6
-20.56 1959.6 164.3
-20.62 1994.4 164.9
-20.78 2020.1 165.7
-21    2030.5 166.5
-21.2  2023.6 167.2
-21.33 2037.7 167.9
-21.62 2033.4 168.7
-21.71 2066.2 169.5
-22.01 2077.5 170.2
-22.15 2071.9 170.9
-22.27 2094   171.7
-22.29 2070.8 172.5
-22.56 2012.6 173.1
-22.64 2024.7 173.8
-22.77 2072.3 174.5
-22.88 2120.6 175.3
-22.92 2165   176.045
-22.91 2223.3  176.727
-22.94 2221.4  177.481
-23.03 2230.95 178.268
-23.13 2279.22 179.694
-23.22 2265.48 180.335
-23.32 2268.29 181.094
-23.4  2238.57 181.915
-23.45 2251.68 182.634
-23.51 2292.02 183.337
-23.56 2332.61 184.103
-23.63 2381.01 184.894
-23.75 2422.59 185.553
-23.81 2448.01 186.203
-23.87 2471.86 186.926
-23.94 2476.67 187.68
-24    2508.7  188.299
-24.07 2538.05 188.906
-24.12 2586.26 189.631
-24.29 2604.62 190.362
-24.35 2666.69 190.954
-24.41 2697.54 191.56
-24.52 2729.63 192.256
-24.64 2739.75 192.938
-24.77 2808.88 193.467
-24.88 2846.34 193.994
-25.01 2898.79 194.647
-25.17 2970.48 195.279
-25.32 3042.35 195.763
-25.53 3055.53 196.277
-25.79 3076.51 196.877
-26.02 3102.36 197.481
-26.14 3127.15 197.967
-26.31 3129.53 198.455
-26.6  3154.19 199.012
-26.9  3177.98 199.572
-27.21 3236.18 199.995
-27.49 3292.07 200.452
-27.75 3316.11 200.997
-28.12 3331.22 201.538
-28.39 3381.86 201.955
-28.73 3390.23 202.419
-29.14 3409.65 202.986
-29.51 3392.6  203.584
-29.94 3386.49 204.086
-30.36 3391.61 204.721
-30.61 3422.95 205.419
-31.02 3389.36 206.13
-31.5  3481.4  206.763
-31.93 3500.95 207.362
-32.27 3523.8  208
-32.54 3533.79 208.642
-33.02 3604.73 209.142
-33.2  3687.9  209.637
-33.49 3726.18 210.181
-33.95 3790.44 210.737
-34.36 3892.22 211.192
-34.94 3919.01 211.663
-35.61 3907.08 212.191
-36.29 3947.11 212.708
-37.01 3908.15 213.144
-37.79 3922.57 213.602
-38.96 3879.98 214.147
-40.13 3854.13 214.7
-41.05 3800.93 215.135
-41.66 3835.21 215.652
-42.41 3907.02 216.289
-43.19 3952.48 216.848
-43.69 4044.59 217.314
-44.15 4072.19 217.776
-44.77 4088.49 218.338
-45.57 4126.39 218.917
-46.32 4176.28 219.427
-47.07 4260.08 219.956
-47.66 4329.46 220.573
-48.63 4328.33 221.201
-49.42 4345.51 221.719
-50.41 4510.73 222.281
-51.27 4552.14 222.933
-52.35 4603.65 223.583
-53.51 4605.65 224.152
-54.65 4615.64 224.737
-55.82 4644.93 225.418
-56.92 4656.23 226.117
-58.18 4678.96 226.754
-59.55 4566.62 227.389
-61.01 4562.25 228.07
-62.59 4651.86 228.689
-64.15 4739.16 229.155
-65.37 4696.82 229.674
-66.65 4753.02 230.301
-67.87 4693.76 230.903
-68.86 4615.89 231.395
-69.72 4634.88 231.906
-70.66 4612.08 232.498
-71.44 4618.26 233.074
-72.08 4662.97 233.546
-72.83 4763.57 234.028
-73.48 4849    234.603
-74.19 4939.23 235.153
-75.02 5053.56 235.605
-75.58 5132.87 236.082
-76.25 5170.34 236.657
-76.81 5203.68 237.232
-77.63 5257.26 237.673
-78.25 5283.73 238.176
-78.76 5359.6  238.789
-79.45 5393.57 239.387
-79.81 5460.83 239.861
-80.22 5466.95 240.368
-80.84 5496.29 240.962
-81.45 5526.77 241.539
-82.09 5561.8  242.009
-82.68 5618    242.52
-83.33 5667.39 243.12
-84.09 5750.57 243.721
-84.67 5785.29 244.208
-85.56 5844.05 244.716
-86.66 5878.7  245.354
-87.44 5952.83 245.966
-88.45 6010.96 246.46
-89.39 6055.61 247.017
-90.13 6087.96 247.698
-90.88 6093.51 248.374
-92    6152.59 248.928
-93.18 6171.57 249.564
-94.14 6142.1  250.299
-95.11 6078.96 251.031
-96.27 6047.49 251.65
-97    6074.66 252.295
-97.7  6090.14 253.033
-98.31 6105.25 253.743
-99.13 6175.69 254.338
-99.79 6214.22 255.032
-100.17 6260.74 255.815
-100.88 6327.12 256.543
-101.84 6327.93 257.151
-102.35 6359.9  257.785
-102.83 6393.5  258.516
-103.51 6476.86 259.191
-104.13 6524.5  259.738
-104.71 6600.31 260.351
-105.39 6629.47 261.04
-106.09 6688.61 261.692
-106.75 6717.46 262.236
-107.24 6724.2  262.847
-107.75 6779.53 263.527
-108.29 6825.8  264.169
-108.91 6882    264.681
-109.24 6983.91 265.258
-109.74 7020    265.887
-110.23 7093.12 266.491
-111    7166.68 266.987
-111.43 7236.5  267.545
-111.76 7311.24 268.171
-112.08 7364.63 268.815
-];
-%GDPD  GDPQ   GPOP
-
-series = zeros(193,2);
-series(:,2) = data_q(:,1);
-series(:,1) = 1000*data_q(:,2)./data_q(:,3);
-
-Y_obs = series(:,1);
-P_obs = series(:,2);
-
-series = series(2:193,:)./series(1:192,:);
-
-gy_obs = series(:,1);
-gp_obs = series(:,2);
-
+data_q = [
+18.02 1474.5 150.2
+17.94 1538.2 150.9
+18.01 1584.5 151.4
+18.42 1644.1 152
+18.73 1678.6 152.7
+19.46 1693.1 153.3
+19.55 1724   153.9
+19.56 1758.2 154.7
+19.79 1760.6 155.4
+19.77 1779.2 156
+19.82 1778.8 156.6
+20.03 1790.9 157.3
+20.12 1846   158
+20.1  1882.6 158.6
+20.14 1897.3 159.2
+20.22 1887.4 160
+20.27 1858.2 160.7
+20.34 1849.9 161.4
+20.39 1848.5 162
+20.42 1868.9 162.8
+20.47 1905.6 163.6
+20.56 1959.6 164.3
+20.62 1994.4 164.9
+20.78 2020.1 165.7
+21    2030.5 166.5
+21.2  2023.6 167.2
+21.33 2037.7 167.9
+21.62 2033.4 168.7
+21.71 2066.2 169.5
+22.01 2077.5 170.2
+22.15 2071.9 170.9
+22.27 2094   171.7
+22.29 2070.8 172.5
+22.56 2012.6 173.1
+22.64 2024.7 173.8
+22.77 2072.3 174.5
+22.88 2120.6 175.3
+22.92 2165   176.045
+22.91 2223.3  176.727
+22.94 2221.4  177.481
+23.03 2230.95 178.268
+23.13 2279.22 179.694
+23.22 2265.48 180.335
+23.32 2268.29 181.094
+23.4  2238.57 181.915
+23.45 2251.68 182.634
+23.51 2292.02 183.337
+23.56 2332.61 184.103
+23.63 2381.01 184.894
+23.75 2422.59 185.553
+23.81 2448.01 186.203
+23.87 2471.86 186.926
+23.94 2476.67 187.68
+24    2508.7  188.299
+24.07 2538.05 188.906
+24.12 2586.26 189.631
+24.29 2604.62 190.362
+24.35 2666.69 190.954
+24.41 2697.54 191.56
+24.52 2729.63 192.256
+24.64 2739.75 192.938
+24.77 2808.88 193.467
+24.88 2846.34 193.994
+25.01 2898.79 194.647
+25.17 2970.48 195.279
+25.32 3042.35 195.763
+25.53 3055.53 196.277
+25.79 3076.51 196.877
+26.02 3102.36 197.481
+26.14 3127.15 197.967
+26.31 3129.53 198.455
+26.6  3154.19 199.012
+26.9  3177.98 199.572
+27.21 3236.18 199.995
+27.49 3292.07 200.452
+27.75 3316.11 200.997
+28.12 3331.22 201.538
+28.39 3381.86 201.955
+28.73 3390.23 202.419
+29.14 3409.65 202.986
+29.51 3392.6  203.584
+29.94 3386.49 204.086
+30.36 3391.61 204.721
+30.61 3422.95 205.419
+31.02 3389.36 206.13
+31.5  3481.4  206.763
+31.93 3500.95 207.362
+32.27 3523.8  208
+32.54 3533.79 208.642
+33.02 3604.73 209.142
+33.2  3687.9  209.637
+33.49 3726.18 210.181
+33.95 3790.44 210.737
+34.36 3892.22 211.192
+34.94 3919.01 211.663
+35.61 3907.08 212.191
+36.29 3947.11 212.708
+37.01 3908.15 213.144
+37.79 3922.57 213.602
+38.96 3879.98 214.147
+40.13 3854.13 214.7
+41.05 3800.93 215.135
+41.66 3835.21 215.652
+42.41 3907.02 216.289
+43.19 3952.48 216.848
+43.69 4044.59 217.314
+44.15 4072.19 217.776
+44.77 4088.49 218.338
+45.57 4126.39 218.917
+46.32 4176.28 219.427
+47.07 4260.08 219.956
+47.66 4329.46 220.573
+48.63 4328.33 221.201
+49.42 4345.51 221.719
+50.41 4510.73 222.281
+51.27 4552.14 222.933
+52.35 4603.65 223.583
+53.51 4605.65 224.152
+54.65 4615.64 224.737
+55.82 4644.93 225.418
+56.92 4656.23 226.117
+58.18 4678.96 226.754
+59.55 4566.62 227.389
+61.01 4562.25 228.07
+62.59 4651.86 228.689
+64.15 4739.16 229.155
+65.37 4696.82 229.674
+66.65 4753.02 230.301
+67.87 4693.76 230.903
+68.86 4615.89 231.395
+69.72 4634.88 231.906
+70.66 4612.08 232.498
+71.44 4618.26 233.074
+72.08 4662.97 233.546
+72.83 4763.57 234.028
+73.48 4849    234.603
+74.19 4939.23 235.153
+75.02 5053.56 235.605
+75.58 5132.87 236.082
+76.25 5170.34 236.657
+76.81 5203.68 237.232
+77.63 5257.26 237.673
+78.25 5283.73 238.176
+78.76 5359.6  238.789
+79.45 5393.57 239.387
+79.81 5460.83 239.861
+80.22 5466.95 240.368
+80.84 5496.29 240.962
+81.45 5526.77 241.539
+82.09 5561.8  242.009
+82.68 5618    242.52
+83.33 5667.39 243.12
+84.09 5750.57 243.721
+84.67 5785.29 244.208
+85.56 5844.05 244.716
+86.66 5878.7  245.354
+87.44 5952.83 245.966
+88.45 6010.96 246.46
+89.39 6055.61 247.017
+90.13 6087.96 247.698
+90.88 6093.51 248.374
+92    6152.59 248.928
+93.18 6171.57 249.564
+94.14 6142.1  250.299
+95.11 6078.96 251.031
+96.27 6047.49 251.65
+97    6074.66 252.295
+97.7  6090.14 253.033
+98.31 6105.25 253.743
+99.13 6175.69 254.338
+99.79 6214.22 255.032
+100.17 6260.74 255.815
+100.88 6327.12 256.543
+101.84 6327.93 257.151
+102.35 6359.9  257.785
+102.83 6393.5  258.516
+103.51 6476.86 259.191
+104.13 6524.5  259.738
+104.71 6600.31 260.351
+105.39 6629.47 261.04
+106.09 6688.61 261.692
+106.75 6717.46 262.236
+107.24 6724.2  262.847
+107.75 6779.53 263.527
+108.29 6825.8  264.169
+108.91 6882    264.681
+109.24 6983.91 265.258
+109.74 7020    265.887
+110.23 7093.12 266.491
+111    7166.68 266.987
+111.43 7236.5  267.545
+111.76 7311.24 268.171
+112.08 7364.63 268.815
+];
+%GDPD  GDPQ   GPOP
+
+series = zeros(193,2);
+series(:,2) = data_q(:,1);
+series(:,1) = 1000*data_q(:,2)./data_q(:,3);
+
+Y_obs = series(:,1);
+P_obs = series(:,2);
+
+series = series(2:193,:)./series(1:192,:);
+
+gy_obs = series(:,1);
+gp_obs = series(:,2);
+
 ti = [1950:0.25:1997.75];
\ No newline at end of file
diff --git a/tests/block_bytecode/example1_varexo_det_bytecode.mod b/tests/block_bytecode/example1_varexo_det_bytecode.mod
index e567161f90..7bad4480c2 100644
--- a/tests/block_bytecode/example1_varexo_det_bytecode.mod
+++ b/tests/block_bytecode/example1_varexo_det_bytecode.mod
@@ -1,58 +1,58 @@
-// Test for varexo_det and forecast command at order 1
-
-var y, c, k, a, h, b;
-varexo e,u;
-varexo_det ahat, bhat;
-
-parameters beta, rho, alpha, delta, theta, psi, tau;
-
-alpha = 0.36;
-rho   = 0.95;
-tau   = 0.025;
-beta  = 0.99;
-delta = 0.025;
-psi   = 0;
-theta = 2.95;
-
-phi   = 0.1;
-
-//model(bytecode);
-model;
-c*theta*h^(1+psi)=(1-alpha)*y;
-k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
-    *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
-y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
-k = exp(b)*(y-c)+(1-delta)*k(-1);
-a = ahat+ rho*a(-1)+tau*b(-1) + e;
-b = bhat+ tau*a(-1)+rho*b(-1) + u;
-end;
-
-initval;
-y = 1.08068253095672;
-c = 0.80359242014163;
-h = 0.29175631001732;
-k = 5;
-a = 0;
-b = 0;
-e = 0;
-u = 0;
-ahat = 0;
-bhat = 0;
-end;
-
-//simul(periods=20);
-shocks;
-var e; stderr 0.009;
-var u; stderr 0.009;
-var e, u = phi*0.009*0.009;
-var ahat;
-periods 1;
-values 0.1;
-var bhat;
-periods 2;
-values 0.2;
-end;
-
-stoch_simul(order=1,irf=0,noprint);
-
-forecast(periods=20);
+// Test for varexo_det and forecast command at order 1
+
+var y, c, k, a, h, b;
+varexo e,u;
+varexo_det ahat, bhat;
+
+parameters beta, rho, alpha, delta, theta, psi, tau;
+
+alpha = 0.36;
+rho   = 0.95;
+tau   = 0.025;
+beta  = 0.99;
+delta = 0.025;
+psi   = 0;
+theta = 2.95;
+
+phi   = 0.1;
+
+//model(bytecode);
+model;
+c*theta*h^(1+psi)=(1-alpha)*y;
+k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
+    *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
+y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
+k = exp(b)*(y-c)+(1-delta)*k(-1);
+a = ahat+ rho*a(-1)+tau*b(-1) + e;
+b = bhat+ tau*a(-1)+rho*b(-1) + u;
+end;
+
+initval;
+y = 1.08068253095672;
+c = 0.80359242014163;
+h = 0.29175631001732;
+k = 5;
+a = 0;
+b = 0;
+e = 0;
+u = 0;
+ahat = 0;
+bhat = 0;
+end;
+
+//simul(periods=20);
+shocks;
+var e; stderr 0.009;
+var u; stderr 0.009;
+var e, u = phi*0.009*0.009;
+var ahat;
+periods 1;
+values 0.1;
+var bhat;
+periods 2;
+values 0.2;
+end;
+
+stoch_simul(order=1,irf=0,noprint);
+
+forecast(periods=20);
diff --git a/tests/dsge-var/dsgevar_forward_calibrated_lambda.mod b/tests/dsge-var/dsgevar_forward_calibrated_lambda.mod
index 0f86390617..6ebf5c2792 100644
--- a/tests/dsge-var/dsgevar_forward_calibrated_lambda.mod
+++ b/tests/dsge-var/dsgevar_forward_calibrated_lambda.mod
@@ -1,79 +1,79 @@
-//$ Declaration of the endogenous variables of the DSGE model.
-var a g mc mrs n winf pie r rw y;
-
-//$ Declaration of the exogenous variables of the DSGE model.
-varexo e_a e_g e_lam e_ms;
-
-//$ Declaration of the deep parameters
-parameters invsig delta gam rho gampie gamy rhoa rhog bet
-	   thetabig omega eps ;
-
-eps=6;
-thetabig=2;
-bet=0.99;
-invsig=2.5;
-gampie=1.5;
-gamy=0.125;
-gam=1;
-delta=0.36;
-omega=0.54;
-rhoa=0.5;
-rhog=0.5;
-rho=0.5;
-
-
-//$ Specification of the DSGE model used as a prior of the VAR model.
-model(linear);
-
-	y=y(+1)-(1/invsig)*(r-pie(+1)+g(+1)-g);
-	y=a+(1-delta)*n;
-	mc=rw+n-y;
-	mrs=invsig*y+gam*n-g;
-	r=rho*r(-1)+(1-rho)*(gampie*pie+gamy*y)+e_ms;
-	rw=rw(-1)+winf-pie;
-	a=rhoa*a(-1)+e_a;
-	g=rhog*g(-1)+e_g;
-	rw=mrs;
-
-	//$ HYBRID PHILLIPS CURVED USED FOR THE SUMULATIONS:
-	//   pie = (omega/(1+omega*bet))*pie(-1)+(bet/(1+omega*bet))*pie(1)+(1-delta)*
-      	//   (1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))/(1+omega*bet)*(mc+e_lam);
-
-	//$ FORWARD LOOKING PHILLIPS CURVE:
-	    pie=bet*pie(+1)+(1-delta)*(1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))*(mc+e_lam);
-end;
-
-
-
-//$ Declaration of the prior beliefs about the deep parameters.
-estimated_params;
-    stderr e_a, uniform_pdf,,,0,2;
-    stderr e_g, uniform_pdf,,,0,2;
-    stderr e_ms, uniform_pdf,,,0,2;
-    stderr e_lam, uniform_pdf,,,0,2;
-
-    invsig, gamma_pdf, 2.5, 1.76;
-    gam, normal_pdf, 1, 0.5;
-    rho, uniform_pdf,,,0,1;
-    gampie, normal_pdf, 1.5, 0.25;
-    gamy, gamma_pdf, 0.125, 0.075;
-    rhoa, uniform_pdf,,,0,1;
-    rhog, uniform_pdf,,,0,1;
-    thetabig, gamma_pdf, 3, 1.42, 1, ;
-
-    //$Parameter for the hybrid Phillips curve
-    //omega, uniform_pdf,,,0,1;
-
-end;
-
-
-//$ Declaration of the observed endogenous variables. Note that they are the variables of the VAR (4 by default) and that we must
-//$ have as many observed variables as exogenous variables.
-varobs pie r rw y;
-
-options_.gradient_method = 3;
-
-//$ The option bayesian_irf triggers the computation of the DSGE-VAR and DSGE posterior distribution of the IRFs.
-//$ The Dashed lines are the first, fifth (ie the median) and ninth posterior deciles of the DSGE-VAR's IRFs, the bold dark curve is the
-//$ posterior median of the DSGE's IRfs and the shaded surface covers the space between the first and ninth posterior deciles of the DSGE's IRFs.
-estimation(datafile=datarabanal_hybrid,first_obs=50,mh_nblocks = 1,nobs=90,dsge_var=.8,mode_compute=4,mh_replic=2000,bayesian_irf);
+//$ Declaration of the endogenous variables of the DSGE model.
+var a g mc mrs n winf pie r rw y;
+
+//$ Declaration of the exogenous variables of the DSGE model.
+varexo e_a e_g e_lam e_ms;
+
+//$ Declaration of the deep parameters
+parameters invsig delta gam rho gampie gamy rhoa rhog bet
+	   thetabig omega eps ;
+
+eps=6;
+thetabig=2;
+bet=0.99;
+invsig=2.5;
+gampie=1.5;
+gamy=0.125;
+gam=1;
+delta=0.36;
+omega=0.54;
+rhoa=0.5;
+rhog=0.5;
+rho=0.5;
+
+
+//$ Specification of the DSGE model used as a prior of the VAR model.
+model(linear);
+
+	y=y(+1)-(1/invsig)*(r-pie(+1)+g(+1)-g);
+	y=a+(1-delta)*n;
+	mc=rw+n-y;
+	mrs=invsig*y+gam*n-g;
+	r=rho*r(-1)+(1-rho)*(gampie*pie+gamy*y)+e_ms;
+	rw=rw(-1)+winf-pie;
+	a=rhoa*a(-1)+e_a;
+	g=rhog*g(-1)+e_g;
+	rw=mrs;
+
+	//$ HYBRID PHILLIPS CURVED USED FOR THE SUMULATIONS:
+	//   pie = (omega/(1+omega*bet))*pie(-1)+(bet/(1+omega*bet))*pie(1)+(1-delta)*
+      	//   (1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))/(1+omega*bet)*(mc+e_lam);
+
+	//$ FORWARD LOOKING PHILLIPS CURVE:
+	    pie=bet*pie(+1)+(1-delta)*(1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))*(mc+e_lam);
+end;
+
+
+
+//$ Declaration of the prior beliefs about the deep parameters.
+estimated_params;
+    stderr e_a, uniform_pdf,,,0,2;
+    stderr e_g, uniform_pdf,,,0,2;
+    stderr e_ms, uniform_pdf,,,0,2;
+    stderr e_lam, uniform_pdf,,,0,2;
+
+    invsig, gamma_pdf, 2.5, 1.76;
+    gam, normal_pdf, 1, 0.5;
+    rho, uniform_pdf,,,0,1;
+    gampie, normal_pdf, 1.5, 0.25;
+    gamy, gamma_pdf, 0.125, 0.075;
+    rhoa, uniform_pdf,,,0,1;
+    rhog, uniform_pdf,,,0,1;
+    thetabig, gamma_pdf, 3, 1.42, 1, ;
+
+    //$Parameter for the hybrid Phillips curve
+    //omega, uniform_pdf,,,0,1;
+
+end;
+
+
+//$ Declaration of the observed endogenous variables. Note that they are the variables of the VAR (4 by default) and that we must
+//$ have as many observed variables as exogenous variables.
+varobs pie r rw y;
+
+options_.gradient_method = 3;
+
+//$ The option bayesian_irf triggers the computation of the DSGE-VAR and DSGE posterior distribution of the IRFs.
+//$ The Dashed lines are the first, fifth (ie the median) and ninth posterior deciles of the DSGE-VAR's IRFs, the bold dark curve is the
+//$ posterior median of the DSGE's IRfs and the shaded surface covers the space between the first and ninth posterior deciles of the DSGE's IRFs.
+estimation(datafile=datarabanal_hybrid,first_obs=50,mh_nblocks = 1,nobs=90,dsge_var=.8,mode_compute=4,mh_replic=2000,bayesian_irf);
diff --git a/tests/dsge-var/dsgevar_forward_estimated_lambda.mod b/tests/dsge-var/dsgevar_forward_estimated_lambda.mod
index f9ae240a01..a0da9f718b 100644
--- a/tests/dsge-var/dsgevar_forward_estimated_lambda.mod
+++ b/tests/dsge-var/dsgevar_forward_estimated_lambda.mod
@@ -1,80 +1,80 @@
-//$ Declaration of the endogenous variables of the DSGE model.
-var a g mc mrs n winf pie r rw y;
-
-//$ Declaration of the exogenous variables of the DSGE model.
-varexo e_a e_g e_lam e_ms;
-
-//$ Declaration of the deep parameters and of dsge_prior_weight
-parameters invsig delta gam rho gampie gamy rhoa rhog bet
-	   thetabig omega eps ;
-
-eps=6;
-thetabig=2;
-bet=0.99;
-invsig=2.5;
-gampie=1.5;
-gamy=0.125;
-gam=1;
-delta=0.36;
-omega=0.54;
-rhoa=0.5;
-rhog=0.5;
-rho=0.5;
-
-
-//$ Specification of the DSGE model used as a prior of the VAR model.
-model(linear);
-
-	y=y(+1)-(1/invsig)*(r-pie(+1)+g(+1)-g);
-	y=a+(1-delta)*n;
-	mc=rw+n-y;
-	mrs=invsig*y+gam*n-g;
-	r=rho*r(-1)+(1-rho)*(gampie*pie+gamy*y)+e_ms;
-	rw=rw(-1)+winf-pie;
-	a=rhoa*a(-1)+e_a;
-	g=rhog*g(-1)+e_g;
-	rw=mrs;
-
-	//$ HYBRID PHILLIPS CURVED USED FOR THE SUMULATIONS:
-	//   pie = (omega/(1+omega*bet))*pie(-1)+(bet/(1+omega*bet))*pie(1)+(1-delta)*
-      	//   (1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))/(1+omega*bet)*(mc+e_lam);
-
-	//$ FORWARD LOOKING PHILLIPS CURVE:
-	    pie=bet*pie(+1)+(1-delta)*(1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))*(mc+e_lam);
-end;
-
-
-
-//$ Declaration of the prior beliefs about the deep parameters and the weight of the DSGE prior.
-estimated_params;
-    stderr e_a, uniform_pdf,,,0,2;
-    stderr e_g, uniform_pdf,,,0,2;
-    stderr e_ms, uniform_pdf,,,0,2;
-    stderr e_lam, uniform_pdf,,,0,2;
-
-    invsig, gamma_pdf, 2.5, 1.76;
-    gam, normal_pdf, 1, 0.5;
-    rho, uniform_pdf,,,0,1;
-    gampie, normal_pdf, 1.5, 0.25;
-    gamy, gamma_pdf, 0.125, 0.075;
-    rhoa, uniform_pdf,,,0,1;
-    rhog, uniform_pdf,,,0,1;
-    thetabig, gamma_pdf, 3, 1.42, 1, ;
-
-    //$Parameter for the hybrid Phillips curve
-    //omega, uniform_pdf,,,0,1;
-
-    dsge_prior_weight, uniform_pdf,,,0,1.9;
-end;
-
-
-//$ Declaration of the observed endogenous variables. Note that they are the variables of the VAR (4 by default) and that we must
-//$ have as many observed variables as exogenous variables.
-varobs pie r rw y;
-
-options_.gradient_method = 3;
-
-//$ The option bayesian_irf triggers the computation of the DSGE-VAR and DSGE posterior distribution of the IRFs.
-//$ The Dashed lines are the first, fifth (ie the median) and ninth posterior deciles of the DSGE-VAR's IRFs, the bold dark curve is the
-//$ posterior median of the DSGE's IRfs and the shaded surface covers the space between the first and ninth posterior deciles of the DSGE's IRFs.
-estimation(datafile=datarabanal_hybrid,first_obs=50,mh_nblocks = 1,nobs=90,dsge_var,mode_compute=4,mh_replic=2000,bayesian_irf);
+//$ Declaration of the endogenous variables of the DSGE model.
+var a g mc mrs n winf pie r rw y;
+
+//$ Declaration of the exogenous variables of the DSGE model.
+varexo e_a e_g e_lam e_ms;
+
+//$ Declaration of the deep parameters and of dsge_prior_weight
+parameters invsig delta gam rho gampie gamy rhoa rhog bet
+	   thetabig omega eps ;
+
+eps=6;
+thetabig=2;
+bet=0.99;
+invsig=2.5;
+gampie=1.5;
+gamy=0.125;
+gam=1;
+delta=0.36;
+omega=0.54;
+rhoa=0.5;
+rhog=0.5;
+rho=0.5;
+
+
+//$ Specification of the DSGE model used as a prior of the VAR model.
+model(linear);
+
+	y=y(+1)-(1/invsig)*(r-pie(+1)+g(+1)-g);
+	y=a+(1-delta)*n;
+	mc=rw+n-y;
+	mrs=invsig*y+gam*n-g;
+	r=rho*r(-1)+(1-rho)*(gampie*pie+gamy*y)+e_ms;
+	rw=rw(-1)+winf-pie;
+	a=rhoa*a(-1)+e_a;
+	g=rhog*g(-1)+e_g;
+	rw=mrs;
+
+	//$ HYBRID PHILLIPS CURVED USED FOR THE SUMULATIONS:
+	//   pie = (omega/(1+omega*bet))*pie(-1)+(bet/(1+omega*bet))*pie(1)+(1-delta)*
+      	//   (1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))/(1+omega*bet)*(mc+e_lam);
+
+	//$ FORWARD LOOKING PHILLIPS CURVE:
+	    pie=bet*pie(+1)+(1-delta)*(1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))*(mc+e_lam);
+end;
+
+
+
+//$ Declaration of the prior beliefs about the deep parameters and the weight of the DSGE prior.
+estimated_params;
+    stderr e_a, uniform_pdf,,,0,2;
+    stderr e_g, uniform_pdf,,,0,2;
+    stderr e_ms, uniform_pdf,,,0,2;
+    stderr e_lam, uniform_pdf,,,0,2;
+
+    invsig, gamma_pdf, 2.5, 1.76;
+    gam, normal_pdf, 1, 0.5;
+    rho, uniform_pdf,,,0,1;
+    gampie, normal_pdf, 1.5, 0.25;
+    gamy, gamma_pdf, 0.125, 0.075;
+    rhoa, uniform_pdf,,,0,1;
+    rhog, uniform_pdf,,,0,1;
+    thetabig, gamma_pdf, 3, 1.42, 1, ;
+
+    //$Parameter for the hybrid Phillips curve
+    //omega, uniform_pdf,,,0,1;
+
+    dsge_prior_weight, uniform_pdf,,,0,1.9;
+end;
+
+
+//$ Declaration of the observed endogenous variables. Note that they are the variables of the VAR (4 by default) and that we must
+//$ have as many observed variables as exogenous variables.
+varobs pie r rw y;
+
+options_.gradient_method = 3;
+
+//$ The option bayesian_irf triggers the computation of the DSGE-VAR and DSGE posterior distribution of the IRFs.
+//$ The Dashed lines are the first, fifth (ie the median) and ninth posterior deciles of the DSGE-VAR's IRFs, the bold dark curve is the
+//$ posterior median of the DSGE's IRfs and the shaded surface covers the space between the first and ninth posterior deciles of the DSGE's IRFs.
+estimation(datafile=datarabanal_hybrid,first_obs=50,mh_nblocks = 1,nobs=90,dsge_var,mode_compute=4,mh_replic=2000,bayesian_irf);
diff --git a/tests/dsge-var/simul_hybrid.mod b/tests/dsge-var/simul_hybrid.mod
index 130ec4b694..311d3f9d00 100644
--- a/tests/dsge-var/simul_hybrid.mod
+++ b/tests/dsge-var/simul_hybrid.mod
@@ -1,51 +1,51 @@
-var a g mc mrs n pie r rw winf y;
-varexo e_a e_g e_lam e_ms;
-
-parameters invsig delta gam rho gampie gamy rhoa rhog bet 
-    	   thetabig omega eps;
-
-eps=6;
-thetabig=2;
-bet=0.99;
-invsig=2.5;
-gampie=1.5;
-gamy=0.125;
-gam=1;
-delta=0.36;
-omega=0.54;
-rhoa=0.5;
-rhog=0.5;
-rho=0.5;
-
-
-model(linear);
-	y=y(+1)-(1/invsig)*(r-pie(+1)+g(+1)-g);
-	y=a+(1-delta)*n;
-	mc=rw+n-y;
-	mrs=invsig*y+gam*n-g;
-	r=rho*r(-1)+(1-rho)*(gampie*pie+gamy*y)+e_ms;
-	rw=rw(-1)+winf-pie;
-	a=rhoa*a(-1)+e_a;
-	g=rhog*g(-1)+e_g;
-	rw=mrs;
-
-	// HYBRID PHILLIPS CURVED USED FOR THE SUMULATIONS:
-	pie = (omega/(1+omega*bet))*pie(-1)+(bet/(1+omega*bet))*pie(1)+(1-delta)*
-      	(1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))/(1+omega*bet)*(mc+e_lam);
-
-	// FORWARD LOOKING PHILLIPS CURVE:
-	// pie=bet*pie(+1)+(1-delta)*(1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))*(mc+e_lam);
-end;
-
-shocks;
-var e_a; stderr 1;
-var e_g; stderr 1;
-var e_ms; stderr 1;
-var e_lam; stderr 1;
-end;
-
-steady;
-check;
-
-stoch_simul(periods=500,irf=0);
+var a g mc mrs n pie r rw winf y;
+varexo e_a e_g e_lam e_ms;
+
+parameters invsig delta gam rho gampie gamy rhoa rhog bet 
+    	   thetabig omega eps;
+
+eps=6;
+thetabig=2;
+bet=0.99;
+invsig=2.5;
+gampie=1.5;
+gamy=0.125;
+gam=1;
+delta=0.36;
+omega=0.54;
+rhoa=0.5;
+rhog=0.5;
+rho=0.5;
+
+
+model(linear);
+	y=y(+1)-(1/invsig)*(r-pie(+1)+g(+1)-g);
+	y=a+(1-delta)*n;
+	mc=rw+n-y;
+	mrs=invsig*y+gam*n-g;
+	r=rho*r(-1)+(1-rho)*(gampie*pie+gamy*y)+e_ms;
+	rw=rw(-1)+winf-pie;
+	a=rhoa*a(-1)+e_a;
+	g=rhog*g(-1)+e_g;
+	rw=mrs;
+
+	// HYBRID PHILLIPS CURVED USED FOR THE SUMULATIONS:
+	pie = (omega/(1+omega*bet))*pie(-1)+(bet/(1+omega*bet))*pie(1)+(1-delta)*
+      	(1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))/(1+omega*bet)*(mc+e_lam);
+
+	// FORWARD LOOKING PHILLIPS CURVE:
+	// pie=bet*pie(+1)+(1-delta)*(1-(1-1/thetabig)*bet)*(1-(1-1/thetabig))/((1-1/thetabig)*(1+delta*(eps-1)))*(mc+e_lam);
+end;
+
+shocks;
+var e_a; stderr 1;
+var e_g; stderr 1;
+var e_ms; stderr 1;
+var e_lam; stderr 1;
+end;
+
+steady;
+check;
+
+stoch_simul(periods=500,irf=0);
 datatomfile('datarabanal_hybrid',[]);
\ No newline at end of file
diff --git a/tests/ep/linear.mod b/tests/ep/linear.mod
index 5b4fe71227..afc64ca4c3 100644
--- a/tests/ep/linear.mod
+++ b/tests/ep/linear.mod
@@ -1,45 +1,45 @@
-var y pie r;
-varexo e_y e_pie;
-
-parameters delta sigma alpha kappa gamma1 gamma2;
-
-delta =  0.44;
-kappa =  0.18;
-alpha =  0.48;
-sigma = -0.06;
-
-gamma1 = 1.5;
-gamma2 = 0.5;
-
-model(use_dll);
-y  = delta * y(-1)  + (1-delta)*y(+1)+sigma *(r - pie(+1)) + e_y;
-pie  =   alpha * pie(-1) + (1-alpha) * pie(+1) + kappa*y + e_pie;
-r = gamma1*pie+gamma2*y;
-end;
-
-shocks;
-var e_y;
-stderr 0.63;
-var e_pie;
-stderr 0.4;
-end;
-
-steady;
-
-options_.maxit_ = 100;
-options_.ep.verbosity = 0;
-options_.ep.stochastic.status = 0;
-options_.ep.order = 0;
-options_.ep.nnodes = 0;
-options_.console_mode = 0;
-
-ts = extended_path([],100);
-
-options_.ep.stochastic.status = 1;
-options_.ep.order = 1;
-options_.ep.nnodes = 3;
-sts = extended_path([],100);
-
-if max(max(abs(ts-sts))) > 1e-12
-   error('extended path algorithm fails in ./tests/ep/linear.mod')
+var y pie r;
+varexo e_y e_pie;
+
+parameters delta sigma alpha kappa gamma1 gamma2;
+
+delta =  0.44;
+kappa =  0.18;
+alpha =  0.48;
+sigma = -0.06;
+
+gamma1 = 1.5;
+gamma2 = 0.5;
+
+model(use_dll);
+y  = delta * y(-1)  + (1-delta)*y(+1)+sigma *(r - pie(+1)) + e_y;
+pie  =   alpha * pie(-1) + (1-alpha) * pie(+1) + kappa*y + e_pie;
+r = gamma1*pie+gamma2*y;
+end;
+
+shocks;
+var e_y;
+stderr 0.63;
+var e_pie;
+stderr 0.4;
+end;
+
+steady;
+
+options_.maxit_ = 100;
+options_.ep.verbosity = 0;
+options_.ep.stochastic.status = 0;
+options_.ep.order = 0;
+options_.ep.nnodes = 0;
+options_.console_mode = 0;
+
+ts = extended_path([],100);
+
+options_.ep.stochastic.status = 1;
+options_.ep.order = 1;
+options_.ep.nnodes = 3;
+sts = extended_path([],100);
+
+if max(max(abs(ts-sts))) > 1e-12
+   error('extended path algorithm fails in ./tests/ep/linear.mod')
 end
\ No newline at end of file
diff --git a/tests/fs2000/fs2000a_steadystate.m b/tests/fs2000/fs2000a_steadystate.m
index 4833e8b960..0692f23e04 100644
--- a/tests/fs2000/fs2000a_steadystate.m
+++ b/tests/fs2000/fs2000a_steadystate.m
@@ -1,60 +1,60 @@
-% computes the steady state of fs2000 analyticaly
-% largely inspired by the program of F. Schorfheide
-function [ys,check] = fs2000a_steadystate(ys,exe)
-  global M_
-  
-  alp = M_.params(1); 
-  bet = M_.params(2); 
-  gam = M_.params(3); 
-  mst = M_.params(4); 
-  rho = M_.params(5); 
-  psi = M_.params(6); 
-  del = M_.params(7); 
-
-  check = 0;
-  
-  dA = exp(gam);
-  gst = 1/dA;
-  m = mst;
-  
-  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
-  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
-  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
-  n  = xist/(nust+xist);
-  P  = xist + nust;
-  k  = khst*n;
-
-  l  = psi*mst*n/( (1-psi)*(1-n) );
-  c  = mst/P;
-  d  = l - mst + 1;
-  y  = k^alp*n^(1-alp)*gst^alp;
-  R  = mst/bet;
-  W  = l/n;
-  ist  = y-c;
-  q  = 1 - d;
-
-  e = 1;
-  
-  gp_obs = m/dA;
-  gy_obs = dA;
-  
-  P_obs = 1;
-  Y_obs = 1;
-  
-  ys =[
-m     
-P     
-c     
-e     
-W     
-R     
-k     
-d     
-n     
-l     
-gy_obs
-gp_obs
-Y_obs 
-P_obs 
-y     
+% computes the steady state of fs2000 analyticaly
+% largely inspired by the program of F. Schorfheide
+function [ys,check] = fs2000a_steadystate(ys,exe)
+  global M_
+  
+  alp = M_.params(1); 
+  bet = M_.params(2); 
+  gam = M_.params(3); 
+  mst = M_.params(4); 
+  rho = M_.params(5); 
+  psi = M_.params(6); 
+  del = M_.params(7); 
+
+  check = 0;
+  
+  dA = exp(gam);
+  gst = 1/dA;
+  m = mst;
+  
+  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
+  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
+  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
+  n  = xist/(nust+xist);
+  P  = xist + nust;
+  k  = khst*n;
+
+  l  = psi*mst*n/( (1-psi)*(1-n) );
+  c  = mst/P;
+  d  = l - mst + 1;
+  y  = k^alp*n^(1-alp)*gst^alp;
+  R  = mst/bet;
+  W  = l/n;
+  ist  = y-c;
+  q  = 1 - d;
+
+  e = 1;
+  
+  gp_obs = m/dA;
+  gy_obs = dA;
+  
+  P_obs = 1;
+  Y_obs = 1;
+  
+  ys =[
+m     
+P     
+c     
+e     
+W     
+R     
+k     
+d     
+n     
+l     
+gy_obs
+gp_obs
+Y_obs 
+P_obs 
+y     
 dA          ];
\ No newline at end of file
diff --git a/tests/kalman_filter_smoother/fs2000a_steadystate.m b/tests/kalman_filter_smoother/fs2000a_steadystate.m
index 4833e8b960..0692f23e04 100644
--- a/tests/kalman_filter_smoother/fs2000a_steadystate.m
+++ b/tests/kalman_filter_smoother/fs2000a_steadystate.m
@@ -1,60 +1,60 @@
-% computes the steady state of fs2000 analyticaly
-% largely inspired by the program of F. Schorfheide
-function [ys,check] = fs2000a_steadystate(ys,exe)
-  global M_
-  
-  alp = M_.params(1); 
-  bet = M_.params(2); 
-  gam = M_.params(3); 
-  mst = M_.params(4); 
-  rho = M_.params(5); 
-  psi = M_.params(6); 
-  del = M_.params(7); 
-
-  check = 0;
-  
-  dA = exp(gam);
-  gst = 1/dA;
-  m = mst;
-  
-  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
-  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
-  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
-  n  = xist/(nust+xist);
-  P  = xist + nust;
-  k  = khst*n;
-
-  l  = psi*mst*n/( (1-psi)*(1-n) );
-  c  = mst/P;
-  d  = l - mst + 1;
-  y  = k^alp*n^(1-alp)*gst^alp;
-  R  = mst/bet;
-  W  = l/n;
-  ist  = y-c;
-  q  = 1 - d;
-
-  e = 1;
-  
-  gp_obs = m/dA;
-  gy_obs = dA;
-  
-  P_obs = 1;
-  Y_obs = 1;
-  
-  ys =[
-m     
-P     
-c     
-e     
-W     
-R     
-k     
-d     
-n     
-l     
-gy_obs
-gp_obs
-Y_obs 
-P_obs 
-y     
+% computes the steady state of fs2000 analyticaly
+% largely inspired by the program of F. Schorfheide
+function [ys,check] = fs2000a_steadystate(ys,exe)
+  global M_
+  
+  alp = M_.params(1); 
+  bet = M_.params(2); 
+  gam = M_.params(3); 
+  mst = M_.params(4); 
+  rho = M_.params(5); 
+  psi = M_.params(6); 
+  del = M_.params(7); 
+
+  check = 0;
+  
+  dA = exp(gam);
+  gst = 1/dA;
+  m = mst;
+  
+  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
+  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
+  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
+  n  = xist/(nust+xist);
+  P  = xist + nust;
+  k  = khst*n;
+
+  l  = psi*mst*n/( (1-psi)*(1-n) );
+  c  = mst/P;
+  d  = l - mst + 1;
+  y  = k^alp*n^(1-alp)*gst^alp;
+  R  = mst/bet;
+  W  = l/n;
+  ist  = y-c;
+  q  = 1 - d;
+
+  e = 1;
+  
+  gp_obs = m/dA;
+  gy_obs = dA;
+  
+  P_obs = 1;
+  Y_obs = 1;
+  
+  ys =[
+m     
+P     
+c     
+e     
+W     
+R     
+k     
+d     
+n     
+l     
+gy_obs
+gp_obs
+Y_obs 
+P_obs 
+y     
 dA          ];
\ No newline at end of file
diff --git a/tests/kalman_filter_smoother/testsmoother.m b/tests/kalman_filter_smoother/testsmoother.m
index 71ca84a33d..2e633bc234 100644
--- a/tests/kalman_filter_smoother/testsmoother.m
+++ b/tests/kalman_filter_smoother/testsmoother.m
@@ -1,56 +1,56 @@
-load test
-% $$$ Y = Y(1:2,:);
-% $$$ mf = mf(1:2);
-% $$$ H=H(1:2,1:2);
-% $$$ pp = pp-1;
-% $$$ trend =trend(1:2,:);
-Pinf1(1,1) = 1;
-Pstar1(1,1) = 0;
-Pstar1(4,1) = 0;
-Pstar1(1,4) = 0;
-[alphahat1,epsilonhat1,etahat1,a11, aK1] = DiffuseKalmanSmootherH1(T,R,Q,H, ...
-						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
-[alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH3(T,R,Q,H, ...
-						  Pinf1,Pstar1,Y,trend, ...
-						  pp,mm,smpl,mf);
-max(max(abs(alphahat1-alphahat2)))
-max(max(abs(epsilonhat1-epsilonhat2)))
-max(max(abs(etahat1-etahat2)))
-max(max(abs(a11-a12)))
-max(max(abs(aK1-aK2)))
-
-return
-[alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother1(T,R,Q, ...
-						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
-[alphahat2,etahat2,a12, aK2] = DiffuseKalmanSmoother3(T,R,Q, ...
-						  Pinf1,Pstar1,Y,trend, ...
-						  pp,mm,smpl,mf);
-
-
-max(max(abs(alphahat1-alphahat2)))
-max(max(abs(etahat1-etahat2)))
-max(max(abs(a11-a12)))
-%max(max(abs(aK1-aK2)))
-
-
-H = zeros(size(H));
-[alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother1(T,R,Q, ...
-						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
-[alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH1(T,R,Q,H, ...
-						  Pinf1,Pstar1,Y,trend, ...
-						  pp,mm,smpl,mf);
-max(max(abs(alphahat1-alphahat2)))
-max(max(abs(etahat1-etahat2)))
-max(max(abs(a11-a12)))
-%max(max(abs(aK1-aK2)))
-
-
-[alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother3(T,R,Q, ...
-						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
-[alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH3(T,R,Q, H, ...
-						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
-
-max(max(abs(alphahat1-alphahat2)))
-max(max(abs(etahat1-etahat2)))
-max(max(abs(a11-a12)))
-%max(max(abs(aK1-aK2)))
+load test
+% $$$ Y = Y(1:2,:);
+% $$$ mf = mf(1:2);
+% $$$ H=H(1:2,1:2);
+% $$$ pp = pp-1;
+% $$$ trend =trend(1:2,:);
+Pinf1(1,1) = 1;
+Pstar1(1,1) = 0;
+Pstar1(4,1) = 0;
+Pstar1(1,4) = 0;
+[alphahat1,epsilonhat1,etahat1,a11, aK1] = DiffuseKalmanSmootherH1(T,R,Q,H, ...
+						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
+[alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH3(T,R,Q,H, ...
+						  Pinf1,Pstar1,Y,trend, ...
+						  pp,mm,smpl,mf);
+max(max(abs(alphahat1-alphahat2)))
+max(max(abs(epsilonhat1-epsilonhat2)))
+max(max(abs(etahat1-etahat2)))
+max(max(abs(a11-a12)))
+max(max(abs(aK1-aK2)))
+
+return
+[alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother1(T,R,Q, ...
+						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
+[alphahat2,etahat2,a12, aK2] = DiffuseKalmanSmoother3(T,R,Q, ...
+						  Pinf1,Pstar1,Y,trend, ...
+						  pp,mm,smpl,mf);
+
+
+max(max(abs(alphahat1-alphahat2)))
+max(max(abs(etahat1-etahat2)))
+max(max(abs(a11-a12)))
+%max(max(abs(aK1-aK2)))
+
+
+H = zeros(size(H));
+[alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother1(T,R,Q, ...
+						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
+[alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH1(T,R,Q,H, ...
+						  Pinf1,Pstar1,Y,trend, ...
+						  pp,mm,smpl,mf);
+max(max(abs(alphahat1-alphahat2)))
+max(max(abs(etahat1-etahat2)))
+max(max(abs(a11-a12)))
+%max(max(abs(aK1-aK2)))
+
+
+[alphahat1,etahat1,a11, aK1] = DiffuseKalmanSmoother3(T,R,Q, ...
+						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
+[alphahat2,epsilonhat2,etahat2,a12, aK2] = DiffuseKalmanSmootherH3(T,R,Q, H, ...
+						  Pinf1,Pstar1,Y,trend,pp,mm,smpl,mf);
+
+max(max(abs(alphahat1-alphahat2)))
+max(max(abs(etahat1-etahat2)))
+max(max(abs(a11-a12)))
+%max(max(abs(aK1-aK2)))
diff --git a/tests/ls2003/data_ca1.m b/tests/ls2003/data_ca1.m
index b0b4f05461..c28fae1a28 100644
--- a/tests/ls2003/data_ca1.m
+++ b/tests/ls2003/data_ca1.m
@@ -1,100 +1,100 @@
-data = [0.928467646476  11.8716889412   20  0.418037507392  0.227382377518 ...
--0.705994063083 11.7522582094   21.25   1.09254424511   -1.29488274994 ...
--0.511895351926 9.68144025625   17.25   -1.66150408407  0.331508393098 ...
--0.990955971267 10.0890781236   17  1.43016275252   -2.43589670141 ...
--0.981233061806 12.1094840679   18.25   2.91293288733   -0.790246576864 ...
--0.882182844512 8.54559460406   15  0.419579139481  0.358729719566 ...
--0.930893002836 6.19238374422   12.5    -1.48847457959  0.739779938797 ...
-1.53158206947   2.76544271886   11.5    -0.336216769682 0.455559918769 ...
-2.2659052834    5.47418162513   11  0.306436789767  -0.0707985731221 ...
-1.05419803797   6.35698426189   11  0.140700250477  0.620401487202 ...
-1.20161076793   3.4253301593    11  0.461296492351  0.14354323987 ...
-1.73934077971   4.70926070322   11.5    1.35798282982   0.38564694435 ...
-1.71735262584   3.54232079749   12.5    2.9097529155    -0.804308583301 ...
-0.426343657844  3.32719108897   13  1.64214862652   -1.18214664701 ...
-1.67751812324   2.93444727338   11.25   0.344434910651  -1.6529373719 ...
-1.37013301099   4.72303361923   11.75   2.61511526582   0.327684243041 ...
-0.281231073781  4.4893853071    10.5    1.17043449257   1.12855106649 ...
-1.53638992834   3.7325309699    10.25   -0.683947046728 0.11943538737 ...
-1.68081431462   3.34729969129   10  1.41159342106   -1.59065680853 ...
--0.343321601133 5.05563513564   12  1.75117366498   -2.40127764642 ...
-0.873415608666  3.2779996255    10.25   -1.39895866711  0.0971444398216 ...
-0.26399696544   4.78229419828   9.75    0.0914692438124 0.299310457612 ...
--0.562233624818 3.88598638237   9.75    -0.0505384765105    0.332826708151 ...
-2.15161914936   3.84859710132   8.75    -3.44811080489  0.789138678784 ...
-1.2345093726    5.62225030942   9.5 -0.366945407434 2.32974981198 ...
-1.62554967459   4.24667132831   10  -0.800958371402 0.0293183770935 ...
-1.33035402527   2.75248979249   9.75    -0.855723113225 0.852493939813 ...
-1.52078814077   3.53415985826   9.75    -3.37963469203  -1.05133958119 ...
-1.16704983697   4.92754079464   10.75   -3.0142303324   0.459907431978 ...
-0.277213572101  4.55532133037   11.75   -0.851995599415 2.03242034852 ...
-0.842215068977  3.11164509647   12.25   -1.08290421696  0.014323281961 ...
-1.05325028606   4.92882647578   13.5    -1.1953883867   0.706764750654 ...
-0.453051253568  6.82998950103   13.5    0.111803656462  0.088462593153 ...
-0.199885995525  5.82643354662   13.5    -0.920501518421 -0.26504958666 ...
-0.137907999624  2.66076369132   13.5    -1.17122929812  -0.995642430514 ...
-0.721949686709  5.70497876823   14.25   1.19378169018   -1.10644839651 ...
--0.418465249225 3.75861110232   14.75   -1.03131674824  0.188507675831 ...
--0.644028342116 4.15104788154   13.75   -1.48911756546  0.204560913792 ...
--0.848213852668 5.65580324027   12.75   0.677011703877  -0.849628054542 ...
--1.51954076928  11.4866911266   11.25   -0.446024680774 -0.456342350765 ...
-0.265275055215  2.85472749592   9.75    -0.598778202436 -0.907311640831 ...
-0.356162529063  2.29614015658   9.5 -0.46820788432  -1.22130883441 ...
-0.368308864363  -0.539083504685 8   -0.781333991956 0.374007246518 ...
--0.145751412732 1.61507621789   8.25    3.68291932628   1.32438399845 ...
-0.285457283664  2.14334055993   7   1.42819405379   -0.00818660844123 ...
-0.372390129412  1.60000213334   6.25    0.626106424052  -0.10136772765 ...
-0.382720203063  1.72614243263   7.25    4.89631941021   -1.10060711916 ...
-0.737957515573  2.90430582851   6   -0.0422721010314    0.4178952497 ...
-0.649532581668  0.657135682543  6   0.692066153971  0.422299120276 ...
-0.627159201987  1.70352689913   5.75    2.62066711305   -1.29237304034 ...
-0.905441299817  1.95663197267   5.5 1.5949697565    -0.27115830703 ...
-1.49322577898   -2.08741765309  6.25    1.23027694802   0.418336889527 ...
-1.48750731567   -1.57274121871  8   3.01660550994   -0.893958254365 ...
-1.39783858087   2.22623066426   7   -0.80842319214  1.47625453886 ...
-0.89274836317   1.30378081742   8   -0.249485058661 0.159871204185 ...
-0.920652246088  4.1437741965    9.75    2.8204453623    0.178149239655 ...
--0.00264276644799   3.07989972052   8.75    -2.56342461535  2.105998353 ...
-0.0198190461681 0.766283759256  8   -1.15838865989  1.56888883418 ...
-0.440050515311  0.127570085801  7.5 0.0400753569995 0.028914333532 ...
-0.129536637901  1.78174141526   6.75    0.959943962785  0.307781224401 ...
-0.398549827172  3.03606770667   6.5 -0.340209794742 0.100979469478 ...
-1.17174775425   0.629625188037  5.75    0.403003686814  0.902394579377 ...
-0.991163981251  2.50862910684   4.75    -1.44963996982  1.16150986945 ...
-0.967603566096  2.12003739013   4.75    0.610846030775  -0.889994896068 ...
-1.14689383604   1.24185011459   4.75    2.01098091308   -1.73846431001 ...
-1.32593824054   0.990713820685  4.75    -0.0955142989332    -0.0369257308362 ...
-0.861135002644  -0.24744943605  6   1.72793107135   -0.691506789639 ...
-1.26870850151   2.09844764887   6.5 1.50720217572   -1.31399187077 ...
-0.260364987715  1.10650139716   6.5 1.13659047496   0.0720441664643 ...
-1.09731242214   0.490796381346  7.25    4.59123894147   -2.14073070763 ...
-1.63792841781   0.612652594286  6.75    1.79604605035   -0.644363995357 ...
-1.48465576034   0.978295808687  6.75    -2.00753620902  1.39437534964 ...
-1.0987608663    4.25212569087   6.25    -2.58901196498  2.56054320803 ...
-1.42592178132   2.76984518311   6.25    0.888195752358  1.03114549274 ...
-1.52958239462   1.31795955491   6.5 -0.902907564082 -0.0952198893776 ...
-1.0170168994    2.14733589918   7   -1.3054866978   2.68803738466 ...
-0.723253652257  3.43552889347   7.5 1.8213700853    0.592593586195 ...
-1.24720806008   3.87383806577   7.5 0.0522300654168 0.988871238698 ...
-0.482531471239  2.67793287032   7.5 2.9693944293    -0.108591166081 ...
-0.154056100439  0.927269031704  6.75    0.119222057561  3.30489209451 ...
-0.0694865769274 6.65916526788   6.25    0.889014476084  -2.83976849035 ...
--0.121267434867 0.341442615696  5.25    0.323053239216  -3.49289229012 ...
-0.726473690375  -3.5423730964   4   2.19149290449   -3.20855054004 ...
-1.39271709108   2.63121085718   3.75    0.88406577736   0.75622580197 ...
-1.07502077727   5.88578836799   4.25    -2.55088273352  2.89018116374 ...
-0.759049251607  4.24703604223   4.5 0.575687665685  -0.388292506167 ...
-]; 
- 
-data = reshape(data,5,86)'; 
-y_obs = data(:,1); 
-pie_obs = data(:,2); 
-R_obs = data(:,3); 
-de = data(:,4); 
-dq = data(:,5); 
- 
-%Country: Canada 
-%Sample Range: 1981:2 to 2002:3 
-%Observations: 86 
-%Variables: Real GDP Growth [%], Inflation [annualized %], Nom Rate [%], 
-%           Exchange Rate Change [%], Terms of Trade Change [%] 
+data = [0.928467646476  11.8716889412   20  0.418037507392  0.227382377518 ...
+-0.705994063083 11.7522582094   21.25   1.09254424511   -1.29488274994 ...
+-0.511895351926 9.68144025625   17.25   -1.66150408407  0.331508393098 ...
+-0.990955971267 10.0890781236   17  1.43016275252   -2.43589670141 ...
+-0.981233061806 12.1094840679   18.25   2.91293288733   -0.790246576864 ...
+-0.882182844512 8.54559460406   15  0.419579139481  0.358729719566 ...
+-0.930893002836 6.19238374422   12.5    -1.48847457959  0.739779938797 ...
+1.53158206947   2.76544271886   11.5    -0.336216769682 0.455559918769 ...
+2.2659052834    5.47418162513   11  0.306436789767  -0.0707985731221 ...
+1.05419803797   6.35698426189   11  0.140700250477  0.620401487202 ...
+1.20161076793   3.4253301593    11  0.461296492351  0.14354323987 ...
+1.73934077971   4.70926070322   11.5    1.35798282982   0.38564694435 ...
+1.71735262584   3.54232079749   12.5    2.9097529155    -0.804308583301 ...
+0.426343657844  3.32719108897   13  1.64214862652   -1.18214664701 ...
+1.67751812324   2.93444727338   11.25   0.344434910651  -1.6529373719 ...
+1.37013301099   4.72303361923   11.75   2.61511526582   0.327684243041 ...
+0.281231073781  4.4893853071    10.5    1.17043449257   1.12855106649 ...
+1.53638992834   3.7325309699    10.25   -0.683947046728 0.11943538737 ...
+1.68081431462   3.34729969129   10  1.41159342106   -1.59065680853 ...
+-0.343321601133 5.05563513564   12  1.75117366498   -2.40127764642 ...
+0.873415608666  3.2779996255    10.25   -1.39895866711  0.0971444398216 ...
+0.26399696544   4.78229419828   9.75    0.0914692438124 0.299310457612 ...
+-0.562233624818 3.88598638237   9.75    -0.0505384765105    0.332826708151 ...
+2.15161914936   3.84859710132   8.75    -3.44811080489  0.789138678784 ...
+1.2345093726    5.62225030942   9.5 -0.366945407434 2.32974981198 ...
+1.62554967459   4.24667132831   10  -0.800958371402 0.0293183770935 ...
+1.33035402527   2.75248979249   9.75    -0.855723113225 0.852493939813 ...
+1.52078814077   3.53415985826   9.75    -3.37963469203  -1.05133958119 ...
+1.16704983697   4.92754079464   10.75   -3.0142303324   0.459907431978 ...
+0.277213572101  4.55532133037   11.75   -0.851995599415 2.03242034852 ...
+0.842215068977  3.11164509647   12.25   -1.08290421696  0.014323281961 ...
+1.05325028606   4.92882647578   13.5    -1.1953883867   0.706764750654 ...
+0.453051253568  6.82998950103   13.5    0.111803656462  0.088462593153 ...
+0.199885995525  5.82643354662   13.5    -0.920501518421 -0.26504958666 ...
+0.137907999624  2.66076369132   13.5    -1.17122929812  -0.995642430514 ...
+0.721949686709  5.70497876823   14.25   1.19378169018   -1.10644839651 ...
+-0.418465249225 3.75861110232   14.75   -1.03131674824  0.188507675831 ...
+-0.644028342116 4.15104788154   13.75   -1.48911756546  0.204560913792 ...
+-0.848213852668 5.65580324027   12.75   0.677011703877  -0.849628054542 ...
+-1.51954076928  11.4866911266   11.25   -0.446024680774 -0.456342350765 ...
+0.265275055215  2.85472749592   9.75    -0.598778202436 -0.907311640831 ...
+0.356162529063  2.29614015658   9.5 -0.46820788432  -1.22130883441 ...
+0.368308864363  -0.539083504685 8   -0.781333991956 0.374007246518 ...
+-0.145751412732 1.61507621789   8.25    3.68291932628   1.32438399845 ...
+0.285457283664  2.14334055993   7   1.42819405379   -0.00818660844123 ...
+0.372390129412  1.60000213334   6.25    0.626106424052  -0.10136772765 ...
+0.382720203063  1.72614243263   7.25    4.89631941021   -1.10060711916 ...
+0.737957515573  2.90430582851   6   -0.0422721010314    0.4178952497 ...
+0.649532581668  0.657135682543  6   0.692066153971  0.422299120276 ...
+0.627159201987  1.70352689913   5.75    2.62066711305   -1.29237304034 ...
+0.905441299817  1.95663197267   5.5 1.5949697565    -0.27115830703 ...
+1.49322577898   -2.08741765309  6.25    1.23027694802   0.418336889527 ...
+1.48750731567   -1.57274121871  8   3.01660550994   -0.893958254365 ...
+1.39783858087   2.22623066426   7   -0.80842319214  1.47625453886 ...
+0.89274836317   1.30378081742   8   -0.249485058661 0.159871204185 ...
+0.920652246088  4.1437741965    9.75    2.8204453623    0.178149239655 ...
+-0.00264276644799   3.07989972052   8.75    -2.56342461535  2.105998353 ...
+0.0198190461681 0.766283759256  8   -1.15838865989  1.56888883418 ...
+0.440050515311  0.127570085801  7.5 0.0400753569995 0.028914333532 ...
+0.129536637901  1.78174141526   6.75    0.959943962785  0.307781224401 ...
+0.398549827172  3.03606770667   6.5 -0.340209794742 0.100979469478 ...
+1.17174775425   0.629625188037  5.75    0.403003686814  0.902394579377 ...
+0.991163981251  2.50862910684   4.75    -1.44963996982  1.16150986945 ...
+0.967603566096  2.12003739013   4.75    0.610846030775  -0.889994896068 ...
+1.14689383604   1.24185011459   4.75    2.01098091308   -1.73846431001 ...
+1.32593824054   0.990713820685  4.75    -0.0955142989332    -0.0369257308362 ...
+0.861135002644  -0.24744943605  6   1.72793107135   -0.691506789639 ...
+1.26870850151   2.09844764887   6.5 1.50720217572   -1.31399187077 ...
+0.260364987715  1.10650139716   6.5 1.13659047496   0.0720441664643 ...
+1.09731242214   0.490796381346  7.25    4.59123894147   -2.14073070763 ...
+1.63792841781   0.612652594286  6.75    1.79604605035   -0.644363995357 ...
+1.48465576034   0.978295808687  6.75    -2.00753620902  1.39437534964 ...
+1.0987608663    4.25212569087   6.25    -2.58901196498  2.56054320803 ...
+1.42592178132   2.76984518311   6.25    0.888195752358  1.03114549274 ...
+1.52958239462   1.31795955491   6.5 -0.902907564082 -0.0952198893776 ...
+1.0170168994    2.14733589918   7   -1.3054866978   2.68803738466 ...
+0.723253652257  3.43552889347   7.5 1.8213700853    0.592593586195 ...
+1.24720806008   3.87383806577   7.5 0.0522300654168 0.988871238698 ...
+0.482531471239  2.67793287032   7.5 2.9693944293    -0.108591166081 ...
+0.154056100439  0.927269031704  6.75    0.119222057561  3.30489209451 ...
+0.0694865769274 6.65916526788   6.25    0.889014476084  -2.83976849035 ...
+-0.121267434867 0.341442615696  5.25    0.323053239216  -3.49289229012 ...
+0.726473690375  -3.5423730964   4   2.19149290449   -3.20855054004 ...
+1.39271709108   2.63121085718   3.75    0.88406577736   0.75622580197 ...
+1.07502077727   5.88578836799   4.25    -2.55088273352  2.89018116374 ...
+0.759049251607  4.24703604223   4.5 0.575687665685  -0.388292506167 ...
+]; 
+ 
+data = reshape(data,5,86)'; 
+y_obs = data(:,1); 
+pie_obs = data(:,2); 
+R_obs = data(:,3); 
+de = data(:,4); 
+dq = data(:,5); 
+ 
+%Country: Canada 
+%Sample Range: 1981:2 to 2002:3 
+%Observations: 86 
+%Variables: Real GDP Growth [%], Inflation [annualized %], Nom Rate [%], 
+%           Exchange Rate Change [%], Terms of Trade Change [%] 
diff --git a/tests/measurement_errors/data_ca1.m b/tests/measurement_errors/data_ca1.m
index b0b4f05461..c28fae1a28 100644
--- a/tests/measurement_errors/data_ca1.m
+++ b/tests/measurement_errors/data_ca1.m
@@ -1,100 +1,100 @@
-data = [0.928467646476  11.8716889412   20  0.418037507392  0.227382377518 ...
--0.705994063083 11.7522582094   21.25   1.09254424511   -1.29488274994 ...
--0.511895351926 9.68144025625   17.25   -1.66150408407  0.331508393098 ...
--0.990955971267 10.0890781236   17  1.43016275252   -2.43589670141 ...
--0.981233061806 12.1094840679   18.25   2.91293288733   -0.790246576864 ...
--0.882182844512 8.54559460406   15  0.419579139481  0.358729719566 ...
--0.930893002836 6.19238374422   12.5    -1.48847457959  0.739779938797 ...
-1.53158206947   2.76544271886   11.5    -0.336216769682 0.455559918769 ...
-2.2659052834    5.47418162513   11  0.306436789767  -0.0707985731221 ...
-1.05419803797   6.35698426189   11  0.140700250477  0.620401487202 ...
-1.20161076793   3.4253301593    11  0.461296492351  0.14354323987 ...
-1.73934077971   4.70926070322   11.5    1.35798282982   0.38564694435 ...
-1.71735262584   3.54232079749   12.5    2.9097529155    -0.804308583301 ...
-0.426343657844  3.32719108897   13  1.64214862652   -1.18214664701 ...
-1.67751812324   2.93444727338   11.25   0.344434910651  -1.6529373719 ...
-1.37013301099   4.72303361923   11.75   2.61511526582   0.327684243041 ...
-0.281231073781  4.4893853071    10.5    1.17043449257   1.12855106649 ...
-1.53638992834   3.7325309699    10.25   -0.683947046728 0.11943538737 ...
-1.68081431462   3.34729969129   10  1.41159342106   -1.59065680853 ...
--0.343321601133 5.05563513564   12  1.75117366498   -2.40127764642 ...
-0.873415608666  3.2779996255    10.25   -1.39895866711  0.0971444398216 ...
-0.26399696544   4.78229419828   9.75    0.0914692438124 0.299310457612 ...
--0.562233624818 3.88598638237   9.75    -0.0505384765105    0.332826708151 ...
-2.15161914936   3.84859710132   8.75    -3.44811080489  0.789138678784 ...
-1.2345093726    5.62225030942   9.5 -0.366945407434 2.32974981198 ...
-1.62554967459   4.24667132831   10  -0.800958371402 0.0293183770935 ...
-1.33035402527   2.75248979249   9.75    -0.855723113225 0.852493939813 ...
-1.52078814077   3.53415985826   9.75    -3.37963469203  -1.05133958119 ...
-1.16704983697   4.92754079464   10.75   -3.0142303324   0.459907431978 ...
-0.277213572101  4.55532133037   11.75   -0.851995599415 2.03242034852 ...
-0.842215068977  3.11164509647   12.25   -1.08290421696  0.014323281961 ...
-1.05325028606   4.92882647578   13.5    -1.1953883867   0.706764750654 ...
-0.453051253568  6.82998950103   13.5    0.111803656462  0.088462593153 ...
-0.199885995525  5.82643354662   13.5    -0.920501518421 -0.26504958666 ...
-0.137907999624  2.66076369132   13.5    -1.17122929812  -0.995642430514 ...
-0.721949686709  5.70497876823   14.25   1.19378169018   -1.10644839651 ...
--0.418465249225 3.75861110232   14.75   -1.03131674824  0.188507675831 ...
--0.644028342116 4.15104788154   13.75   -1.48911756546  0.204560913792 ...
--0.848213852668 5.65580324027   12.75   0.677011703877  -0.849628054542 ...
--1.51954076928  11.4866911266   11.25   -0.446024680774 -0.456342350765 ...
-0.265275055215  2.85472749592   9.75    -0.598778202436 -0.907311640831 ...
-0.356162529063  2.29614015658   9.5 -0.46820788432  -1.22130883441 ...
-0.368308864363  -0.539083504685 8   -0.781333991956 0.374007246518 ...
--0.145751412732 1.61507621789   8.25    3.68291932628   1.32438399845 ...
-0.285457283664  2.14334055993   7   1.42819405379   -0.00818660844123 ...
-0.372390129412  1.60000213334   6.25    0.626106424052  -0.10136772765 ...
-0.382720203063  1.72614243263   7.25    4.89631941021   -1.10060711916 ...
-0.737957515573  2.90430582851   6   -0.0422721010314    0.4178952497 ...
-0.649532581668  0.657135682543  6   0.692066153971  0.422299120276 ...
-0.627159201987  1.70352689913   5.75    2.62066711305   -1.29237304034 ...
-0.905441299817  1.95663197267   5.5 1.5949697565    -0.27115830703 ...
-1.49322577898   -2.08741765309  6.25    1.23027694802   0.418336889527 ...
-1.48750731567   -1.57274121871  8   3.01660550994   -0.893958254365 ...
-1.39783858087   2.22623066426   7   -0.80842319214  1.47625453886 ...
-0.89274836317   1.30378081742   8   -0.249485058661 0.159871204185 ...
-0.920652246088  4.1437741965    9.75    2.8204453623    0.178149239655 ...
--0.00264276644799   3.07989972052   8.75    -2.56342461535  2.105998353 ...
-0.0198190461681 0.766283759256  8   -1.15838865989  1.56888883418 ...
-0.440050515311  0.127570085801  7.5 0.0400753569995 0.028914333532 ...
-0.129536637901  1.78174141526   6.75    0.959943962785  0.307781224401 ...
-0.398549827172  3.03606770667   6.5 -0.340209794742 0.100979469478 ...
-1.17174775425   0.629625188037  5.75    0.403003686814  0.902394579377 ...
-0.991163981251  2.50862910684   4.75    -1.44963996982  1.16150986945 ...
-0.967603566096  2.12003739013   4.75    0.610846030775  -0.889994896068 ...
-1.14689383604   1.24185011459   4.75    2.01098091308   -1.73846431001 ...
-1.32593824054   0.990713820685  4.75    -0.0955142989332    -0.0369257308362 ...
-0.861135002644  -0.24744943605  6   1.72793107135   -0.691506789639 ...
-1.26870850151   2.09844764887   6.5 1.50720217572   -1.31399187077 ...
-0.260364987715  1.10650139716   6.5 1.13659047496   0.0720441664643 ...
-1.09731242214   0.490796381346  7.25    4.59123894147   -2.14073070763 ...
-1.63792841781   0.612652594286  6.75    1.79604605035   -0.644363995357 ...
-1.48465576034   0.978295808687  6.75    -2.00753620902  1.39437534964 ...
-1.0987608663    4.25212569087   6.25    -2.58901196498  2.56054320803 ...
-1.42592178132   2.76984518311   6.25    0.888195752358  1.03114549274 ...
-1.52958239462   1.31795955491   6.5 -0.902907564082 -0.0952198893776 ...
-1.0170168994    2.14733589918   7   -1.3054866978   2.68803738466 ...
-0.723253652257  3.43552889347   7.5 1.8213700853    0.592593586195 ...
-1.24720806008   3.87383806577   7.5 0.0522300654168 0.988871238698 ...
-0.482531471239  2.67793287032   7.5 2.9693944293    -0.108591166081 ...
-0.154056100439  0.927269031704  6.75    0.119222057561  3.30489209451 ...
-0.0694865769274 6.65916526788   6.25    0.889014476084  -2.83976849035 ...
--0.121267434867 0.341442615696  5.25    0.323053239216  -3.49289229012 ...
-0.726473690375  -3.5423730964   4   2.19149290449   -3.20855054004 ...
-1.39271709108   2.63121085718   3.75    0.88406577736   0.75622580197 ...
-1.07502077727   5.88578836799   4.25    -2.55088273352  2.89018116374 ...
-0.759049251607  4.24703604223   4.5 0.575687665685  -0.388292506167 ...
-]; 
- 
-data = reshape(data,5,86)'; 
-y_obs = data(:,1); 
-pie_obs = data(:,2); 
-R_obs = data(:,3); 
-de = data(:,4); 
-dq = data(:,5); 
- 
-%Country: Canada 
-%Sample Range: 1981:2 to 2002:3 
-%Observations: 86 
-%Variables: Real GDP Growth [%], Inflation [annualized %], Nom Rate [%], 
-%           Exchange Rate Change [%], Terms of Trade Change [%] 
+data = [0.928467646476  11.8716889412   20  0.418037507392  0.227382377518 ...
+-0.705994063083 11.7522582094   21.25   1.09254424511   -1.29488274994 ...
+-0.511895351926 9.68144025625   17.25   -1.66150408407  0.331508393098 ...
+-0.990955971267 10.0890781236   17  1.43016275252   -2.43589670141 ...
+-0.981233061806 12.1094840679   18.25   2.91293288733   -0.790246576864 ...
+-0.882182844512 8.54559460406   15  0.419579139481  0.358729719566 ...
+-0.930893002836 6.19238374422   12.5    -1.48847457959  0.739779938797 ...
+1.53158206947   2.76544271886   11.5    -0.336216769682 0.455559918769 ...
+2.2659052834    5.47418162513   11  0.306436789767  -0.0707985731221 ...
+1.05419803797   6.35698426189   11  0.140700250477  0.620401487202 ...
+1.20161076793   3.4253301593    11  0.461296492351  0.14354323987 ...
+1.73934077971   4.70926070322   11.5    1.35798282982   0.38564694435 ...
+1.71735262584   3.54232079749   12.5    2.9097529155    -0.804308583301 ...
+0.426343657844  3.32719108897   13  1.64214862652   -1.18214664701 ...
+1.67751812324   2.93444727338   11.25   0.344434910651  -1.6529373719 ...
+1.37013301099   4.72303361923   11.75   2.61511526582   0.327684243041 ...
+0.281231073781  4.4893853071    10.5    1.17043449257   1.12855106649 ...
+1.53638992834   3.7325309699    10.25   -0.683947046728 0.11943538737 ...
+1.68081431462   3.34729969129   10  1.41159342106   -1.59065680853 ...
+-0.343321601133 5.05563513564   12  1.75117366498   -2.40127764642 ...
+0.873415608666  3.2779996255    10.25   -1.39895866711  0.0971444398216 ...
+0.26399696544   4.78229419828   9.75    0.0914692438124 0.299310457612 ...
+-0.562233624818 3.88598638237   9.75    -0.0505384765105    0.332826708151 ...
+2.15161914936   3.84859710132   8.75    -3.44811080489  0.789138678784 ...
+1.2345093726    5.62225030942   9.5 -0.366945407434 2.32974981198 ...
+1.62554967459   4.24667132831   10  -0.800958371402 0.0293183770935 ...
+1.33035402527   2.75248979249   9.75    -0.855723113225 0.852493939813 ...
+1.52078814077   3.53415985826   9.75    -3.37963469203  -1.05133958119 ...
+1.16704983697   4.92754079464   10.75   -3.0142303324   0.459907431978 ...
+0.277213572101  4.55532133037   11.75   -0.851995599415 2.03242034852 ...
+0.842215068977  3.11164509647   12.25   -1.08290421696  0.014323281961 ...
+1.05325028606   4.92882647578   13.5    -1.1953883867   0.706764750654 ...
+0.453051253568  6.82998950103   13.5    0.111803656462  0.088462593153 ...
+0.199885995525  5.82643354662   13.5    -0.920501518421 -0.26504958666 ...
+0.137907999624  2.66076369132   13.5    -1.17122929812  -0.995642430514 ...
+0.721949686709  5.70497876823   14.25   1.19378169018   -1.10644839651 ...
+-0.418465249225 3.75861110232   14.75   -1.03131674824  0.188507675831 ...
+-0.644028342116 4.15104788154   13.75   -1.48911756546  0.204560913792 ...
+-0.848213852668 5.65580324027   12.75   0.677011703877  -0.849628054542 ...
+-1.51954076928  11.4866911266   11.25   -0.446024680774 -0.456342350765 ...
+0.265275055215  2.85472749592   9.75    -0.598778202436 -0.907311640831 ...
+0.356162529063  2.29614015658   9.5 -0.46820788432  -1.22130883441 ...
+0.368308864363  -0.539083504685 8   -0.781333991956 0.374007246518 ...
+-0.145751412732 1.61507621789   8.25    3.68291932628   1.32438399845 ...
+0.285457283664  2.14334055993   7   1.42819405379   -0.00818660844123 ...
+0.372390129412  1.60000213334   6.25    0.626106424052  -0.10136772765 ...
+0.382720203063  1.72614243263   7.25    4.89631941021   -1.10060711916 ...
+0.737957515573  2.90430582851   6   -0.0422721010314    0.4178952497 ...
+0.649532581668  0.657135682543  6   0.692066153971  0.422299120276 ...
+0.627159201987  1.70352689913   5.75    2.62066711305   -1.29237304034 ...
+0.905441299817  1.95663197267   5.5 1.5949697565    -0.27115830703 ...
+1.49322577898   -2.08741765309  6.25    1.23027694802   0.418336889527 ...
+1.48750731567   -1.57274121871  8   3.01660550994   -0.893958254365 ...
+1.39783858087   2.22623066426   7   -0.80842319214  1.47625453886 ...
+0.89274836317   1.30378081742   8   -0.249485058661 0.159871204185 ...
+0.920652246088  4.1437741965    9.75    2.8204453623    0.178149239655 ...
+-0.00264276644799   3.07989972052   8.75    -2.56342461535  2.105998353 ...
+0.0198190461681 0.766283759256  8   -1.15838865989  1.56888883418 ...
+0.440050515311  0.127570085801  7.5 0.0400753569995 0.028914333532 ...
+0.129536637901  1.78174141526   6.75    0.959943962785  0.307781224401 ...
+0.398549827172  3.03606770667   6.5 -0.340209794742 0.100979469478 ...
+1.17174775425   0.629625188037  5.75    0.403003686814  0.902394579377 ...
+0.991163981251  2.50862910684   4.75    -1.44963996982  1.16150986945 ...
+0.967603566096  2.12003739013   4.75    0.610846030775  -0.889994896068 ...
+1.14689383604   1.24185011459   4.75    2.01098091308   -1.73846431001 ...
+1.32593824054   0.990713820685  4.75    -0.0955142989332    -0.0369257308362 ...
+0.861135002644  -0.24744943605  6   1.72793107135   -0.691506789639 ...
+1.26870850151   2.09844764887   6.5 1.50720217572   -1.31399187077 ...
+0.260364987715  1.10650139716   6.5 1.13659047496   0.0720441664643 ...
+1.09731242214   0.490796381346  7.25    4.59123894147   -2.14073070763 ...
+1.63792841781   0.612652594286  6.75    1.79604605035   -0.644363995357 ...
+1.48465576034   0.978295808687  6.75    -2.00753620902  1.39437534964 ...
+1.0987608663    4.25212569087   6.25    -2.58901196498  2.56054320803 ...
+1.42592178132   2.76984518311   6.25    0.888195752358  1.03114549274 ...
+1.52958239462   1.31795955491   6.5 -0.902907564082 -0.0952198893776 ...
+1.0170168994    2.14733589918   7   -1.3054866978   2.68803738466 ...
+0.723253652257  3.43552889347   7.5 1.8213700853    0.592593586195 ...
+1.24720806008   3.87383806577   7.5 0.0522300654168 0.988871238698 ...
+0.482531471239  2.67793287032   7.5 2.9693944293    -0.108591166081 ...
+0.154056100439  0.927269031704  6.75    0.119222057561  3.30489209451 ...
+0.0694865769274 6.65916526788   6.25    0.889014476084  -2.83976849035 ...
+-0.121267434867 0.341442615696  5.25    0.323053239216  -3.49289229012 ...
+0.726473690375  -3.5423730964   4   2.19149290449   -3.20855054004 ...
+1.39271709108   2.63121085718   3.75    0.88406577736   0.75622580197 ...
+1.07502077727   5.88578836799   4.25    -2.55088273352  2.89018116374 ...
+0.759049251607  4.24703604223   4.5 0.575687665685  -0.388292506167 ...
+]; 
+ 
+data = reshape(data,5,86)'; 
+y_obs = data(:,1); 
+pie_obs = data(:,2); 
+R_obs = data(:,3); 
+de = data(:,4); 
+dq = data(:,5); 
+ 
+%Country: Canada 
+%Sample Range: 1981:2 to 2002:3 
+%Observations: 86 
+%Variables: Real GDP Growth [%], Inflation [annualized %], Nom Rate [%], 
+%           Exchange Rate Change [%], Terms of Trade Change [%] 
diff --git a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m
index 621a59411a..ce6156c7b9 100644
--- a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m
+++ b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m
@@ -1,228 +1,228 @@
-function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol3v(lags,nvar,nStates,indxEqnTv_m,nexo)
-% Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
-%           All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
-%             of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
-%
-% Variables: Pcom, M2, FFR, y, P, U.  Equations: information, policy, money demand, y, P, U.
-% Exporting orthonormal matrices for the deterministic linear restrictions
-%     (equation by equation) with time-varying A0 and D+** equations.
-% See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
-%
-% lags: Maximum length of lag.
-% nvar:  Number of endogeous variables.
-% nStates:  Number of states.
-% indxEqnTv_m: nvar-by-2. Stores equation characteristics.
-%                   1st column: labels of equations [1:nvar]'.
-%                   2nd column: labels of time-varying features with
-%                        1: indxConst -- all coefficients are constant,
-%                        2: indxStv -- only shocks are time-varying,
-%                        3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
-%                        4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
-%                        5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant.
-%          So far this function is written to handle one exogenous variable, which is a constant term.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters
-%           within the state and si is the number of free states.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
-% Vi: nvar-by-1 cell.  In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters within the state and si is the number of free states.
-%           With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
-%           parameters and gi is a vector of free parameters.  The ith equation is in the order of [nvar variables
-%           for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
-%           variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
-% n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
-% np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
-%
-% Tao Zha, February 2003
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
-np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
-
-if (nargin==3)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-end
-
-
-n = nvar*nStates;
-kvar=lags*nvar+nexo;  % Maximum number of lagged and exogenous variables in each equation under each state.
-k = kvar*nStates;  % Maximum number of lagged and exogenous variables in each equation in all states.
-
-Qi = zeros(n,n,nvar);   % 3rd dim: nvar contemporaneous equations.
-Ri = zeros(k,k,nvar);    % 1st and 2nd dims: lagged and exogenous equations.
-   % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
-   %        0 means no restriction.
-   %        1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
-   %        1 (only 1) means that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time for A0_s.
-%-------------------------------------------------------------
-%
-
-%======== The first equation ===========
-eqninx = 1;
-nreseqn = 2;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0      -1  0  0
-      0  1  0       0 -1  0
-      0  0  1       0  0 -1
-
-      0 0 0       0 1 0
-      0 0 0       0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 1 0       0 0 0
-      0 0 1       0 0 0
-
-      0 0 0       0 1 0
-      0 0 0       0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_*.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The second equation ===========
-eqninx = 2;
-nreseqn = 1;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0     -1  0  0
-      0  1  0      0 -1  0
-      0  0  1      0  0 -1
-
-      0 0 0      0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 1       0 0 0
-
-      0 0 0      0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_3s_case3a.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-
-   %==== For freely time-varying A+ for only the first 6 lags.
-   %====       Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
-   %  nlagsno0 = 6;   % Number of lags to be nonzero.
-   %  for si=1:nStates
-   %     for ki = 1:lags-nlagsno0
-   %        for kj=1:nvar
-   %           Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
-   %        end
-   %     end
-   %  end
-   %**** For constant D+_s except the first two lags and the constant term.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   %  for si=1:nStates-1
-   %     for ki=[2*nvar+1:kvar-1]
-   %        Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-   %     end
-   %  end
-end
-
-
-%======== The third equation (money demand) ===========
-eqninx = 3;
-nreseqn = 0;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0      -1  0  0
-      0  1  0       0 -1  0
-      0  0  1       0  0 -1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_*.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-
-for ki=1:nvar   %  initializing loop for each equation
-   Ui{ki} = null(Qi(:,:,ki));
-   Vi{ki} = null(Ri(:,:,ki));
-   n0(ki) = size(Ui{ki},2);
-   np(ki) = size(Vi{ki},2);
-end
+function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol3v(lags,nvar,nStates,indxEqnTv_m,nexo)
+% Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
+%           All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
+%             of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
+%
+% Variables: Pcom, M2, FFR, y, P, U.  Equations: information, policy, money demand, y, P, U.
+% Exporting orthonormal matrices for the deterministic linear restrictions
+%     (equation by equation) with time-varying A0 and D+** equations.
+% See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
+%
+% lags: Maximum length of lag.
+% nvar:  Number of endogeous variables.
+% nStates:  Number of states.
+% indxEqnTv_m: nvar-by-2. Stores equation characteristics.
+%                   1st column: labels of equations [1:nvar]'.
+%                   2nd column: labels of time-varying features with
+%                        1: indxConst -- all coefficients are constant,
+%                        2: indxStv -- only shocks are time-varying,
+%                        3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
+%                        4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
+%                        5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant.
+%          So far this function is written to handle one exogenous variable, which is a constant term.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters
+%           within the state and si is the number of free states.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
+% Vi: nvar-by-1 cell.  In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters within the state and si is the number of free states.
+%           With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
+%           parameters and gi is a vector of free parameters.  The ith equation is in the order of [nvar variables
+%           for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
+%           variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
+% n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
+% np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
+%
+% Tao Zha, February 2003
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
+np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
+
+if (nargin==3)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+end
+
+
+n = nvar*nStates;
+kvar=lags*nvar+nexo;  % Maximum number of lagged and exogenous variables in each equation under each state.
+k = kvar*nStates;  % Maximum number of lagged and exogenous variables in each equation in all states.
+
+Qi = zeros(n,n,nvar);   % 3rd dim: nvar contemporaneous equations.
+Ri = zeros(k,k,nvar);    % 1st and 2nd dims: lagged and exogenous equations.
+   % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
+   %        0 means no restriction.
+   %        1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
+   %        1 (only 1) means that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time for A0_s.
+%-------------------------------------------------------------
+%
+
+%======== The first equation ===========
+eqninx = 1;
+nreseqn = 2;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0      -1  0  0
+      0  1  0       0 -1  0
+      0  0  1       0  0 -1
+
+      0 0 0       0 1 0
+      0 0 0       0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 1 0       0 0 0
+      0 0 1       0 0 0
+
+      0 0 0       0 1 0
+      0 0 0       0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_*.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The second equation ===========
+eqninx = 2;
+nreseqn = 1;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0     -1  0  0
+      0  1  0      0 -1  0
+      0  0  1      0  0 -1
+
+      0 0 0      0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 1       0 0 0
+
+      0 0 0      0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_3s_case3a.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+
+   %==== For freely time-varying A+ for only the first 6 lags.
+   %====       Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
+   %  nlagsno0 = 6;   % Number of lags to be nonzero.
+   %  for si=1:nStates
+   %     for ki = 1:lags-nlagsno0
+   %        for kj=1:nvar
+   %           Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
+   %        end
+   %     end
+   %  end
+   %**** For constant D+_s except the first two lags and the constant term.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   %  for si=1:nStates-1
+   %     for ki=[2*nvar+1:kvar-1]
+   %        Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+   %     end
+   %  end
+end
+
+
+%======== The third equation (money demand) ===========
+eqninx = 3;
+nreseqn = 0;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0      -1  0  0
+      0  1  0       0 -1  0
+      0  0  1       0  0 -1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_*.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+
+for ki=1:nvar   %  initializing loop for each equation
+   Ui{ki} = null(Qi(:,:,ki));
+   Vi{ki} = null(Ri(:,:,ki));
+   n0(ki) = size(Ui{ki},2);
+   np(ki) = size(Vi{ki},2);
+end
diff --git a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol4v.m b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol4v.m
index d83a90b372..bc3215cdeb 100644
--- a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol4v.m
+++ b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol4v.m
@@ -1,331 +1,331 @@
-function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol4v(lags,nvar,nStates,indxEqnTv_m,nexo)
-% Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
-%           All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
-%             of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
-%
-% Variables: Pcom, M2, FFR, y, P, U.  Equations: information, policy, money demand, y, P, U.
-% Exporting orthonormal matrices for the deterministic linear restrictions
-%     (equation by equation) with time-varying A0 and D+** equations.
-% See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
-%
-% lags: Maximum length of lag.
-% nvar:  Number of endogeous variables.
-% nStates:  Number of states.
-% indxEqnTv_m: nvar-by-2. Stores equation characteristics.
-%                   1st column: labels of equations [1:nvar]'.
-%                   2nd column: labels of time-varying features with
-%                        1: indxConst -- all coefficients are constant,
-%                        2: indxStv -- only shocks are time-varying,
-%                        3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
-%                        4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
-%                        5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant.
-%          So far this function is written to handle one exogenous variable, which is a constant term.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters
-%           within the state and si is the number of free states.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
-% Vi: nvar-by-1 cell.  In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters within the state and si is the number of free states.
-%           With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
-%           parameters and gi is a vector of free parameters.  The ith equation is in the order of [nvar variables
-%           for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
-%           variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
-% n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
-% np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
-%
-% Tao Zha, February 2003
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
-np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
-
-if (nargin==3)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-end
-
-
-n = nvar*nStates;
-kvar=lags*nvar+nexo;  % Maximum number of lagged and exogenous variables in each equation under each state.
-k = kvar*nStates;  % Maximum number of lagged and exogenous variables in each equation in all states.
-
-Qi = zeros(n,n,nvar);   % 3rd dim: nvar contemporaneous equations.
-Ri = zeros(k,k,nvar);    % 1st and 2nd dims: lagged and exogenous equations.
-   % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
-   %        0 means no restriction.
-   %        1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
-   %        1 (only 1) means that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time for A0_s.
-%-------------------------------------------------------------
-%
-
-%======== The first equation ===========
-eqninx = 1;
-nreseqn = 3;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0     -1  0  0  0
-      0  1  0  0      0 -1  0  0
-      0  0  1  0      0  0 -1  0
-      0  0  0  1      0  0  0 -1
-
-      0 0 0 0      0 1 0 0
-      0 0 0 0      0 0 1 0
-      0 0 0 0      0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 1 0 0      0 0 0 0
-      0 0 1 0      0 0 0 0
-      0 0 0 1      0 0 0 0
-
-      0 0 0 0      0 1 0 0
-      0 0 0 0      0 0 1 0
-      0 0 0 0      0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The second equation ===========
-eqninx = 2;
-nreseqn = 2;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0     -1  0  0  0
-      0  1  0  0      0 -1  0  0
-      0  0  1  0      0  0 -1  0
-      0  0  0  1      0  0  0 -1
-
-      0 0 0 0      0 0 1 0
-      0 0 0 0      0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 1 0      0 0 0 0
-      0 0 0 1      0 0 0 0
-
-      0 0 0 0      0 0 1 0
-      0 0 0 0      0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_3s_case3a.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-
-   %==== For freely time-varying A+ for only the first 6 lags.
-   %====       Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
-   %  nlagsno0 = 6;   % Number of lags to be nonzero.
-   %  for si=1:nStates
-   %     for ki = 1:lags-nlagsno0
-   %        for kj=1:nvar
-   %           Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
-   %        end
-   %     end
-   %  end
-   %**** For constant D+_s except the first two lags and the constant term.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   %  for si=1:nStates-1
-   %     for ki=[2*nvar+1:kvar-1]
-   %        Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-   %     end
-   %  end
-end
-
-
-%======== The third equation ===========
-eqninx = 3;
-nreseqn = 1;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0     -1  0  0  0
-      0  1  0  0      0 -1  0  0
-      0  0  1  0      0  0 -1  0
-      0  0  0  1      0  0  0 -1
-
-      0 0 0 0      0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 0 1      0 0 0 0
-
-      0 0 0 0      0 0 0 1
-                         ];
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The fourth equation ===========
-eqninx = 4;
-nreseqn = 0;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0     -1  0  0  0
-      0  1  0  0      0 -1  0  0
-      0  0  1  0      0  0 -1  0
-      0  0  0  1      0  0  0 -1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-
-
-
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-
-for ki=1:nvar   %  initializing loop for each equation
-   Ui{ki} = null(Qi(:,:,ki));
-   Vi{ki} = null(Ri(:,:,ki));
-   n0(ki) = size(Ui{ki},2);
-   np(ki) = size(Vi{ki},2);
-end
+function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol4v(lags,nvar,nStates,indxEqnTv_m,nexo)
+% Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
+%           All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
+%             of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
+%
+% Variables: Pcom, M2, FFR, y, P, U.  Equations: information, policy, money demand, y, P, U.
+% Exporting orthonormal matrices for the deterministic linear restrictions
+%     (equation by equation) with time-varying A0 and D+** equations.
+% See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
+%
+% lags: Maximum length of lag.
+% nvar:  Number of endogeous variables.
+% nStates:  Number of states.
+% indxEqnTv_m: nvar-by-2. Stores equation characteristics.
+%                   1st column: labels of equations [1:nvar]'.
+%                   2nd column: labels of time-varying features with
+%                        1: indxConst -- all coefficients are constant,
+%                        2: indxStv -- only shocks are time-varying,
+%                        3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
+%                        4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
+%                        5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant.
+%          So far this function is written to handle one exogenous variable, which is a constant term.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters
+%           within the state and si is the number of free states.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
+% Vi: nvar-by-1 cell.  In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters within the state and si is the number of free states.
+%           With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
+%           parameters and gi is a vector of free parameters.  The ith equation is in the order of [nvar variables
+%           for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
+%           variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
+% n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
+% np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
+%
+% Tao Zha, February 2003
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
+np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
+
+if (nargin==3)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+end
+
+
+n = nvar*nStates;
+kvar=lags*nvar+nexo;  % Maximum number of lagged and exogenous variables in each equation under each state.
+k = kvar*nStates;  % Maximum number of lagged and exogenous variables in each equation in all states.
+
+Qi = zeros(n,n,nvar);   % 3rd dim: nvar contemporaneous equations.
+Ri = zeros(k,k,nvar);    % 1st and 2nd dims: lagged and exogenous equations.
+   % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
+   %        0 means no restriction.
+   %        1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
+   %        1 (only 1) means that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time for A0_s.
+%-------------------------------------------------------------
+%
+
+%======== The first equation ===========
+eqninx = 1;
+nreseqn = 3;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0     -1  0  0  0
+      0  1  0  0      0 -1  0  0
+      0  0  1  0      0  0 -1  0
+      0  0  0  1      0  0  0 -1
+
+      0 0 0 0      0 1 0 0
+      0 0 0 0      0 0 1 0
+      0 0 0 0      0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 1 0 0      0 0 0 0
+      0 0 1 0      0 0 0 0
+      0 0 0 1      0 0 0 0
+
+      0 0 0 0      0 1 0 0
+      0 0 0 0      0 0 1 0
+      0 0 0 0      0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The second equation ===========
+eqninx = 2;
+nreseqn = 2;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0     -1  0  0  0
+      0  1  0  0      0 -1  0  0
+      0  0  1  0      0  0 -1  0
+      0  0  0  1      0  0  0 -1
+
+      0 0 0 0      0 0 1 0
+      0 0 0 0      0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 1 0      0 0 0 0
+      0 0 0 1      0 0 0 0
+
+      0 0 0 0      0 0 1 0
+      0 0 0 0      0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_3s_case3a.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+
+   %==== For freely time-varying A+ for only the first 6 lags.
+   %====       Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
+   %  nlagsno0 = 6;   % Number of lags to be nonzero.
+   %  for si=1:nStates
+   %     for ki = 1:lags-nlagsno0
+   %        for kj=1:nvar
+   %           Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
+   %        end
+   %     end
+   %  end
+   %**** For constant D+_s except the first two lags and the constant term.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   %  for si=1:nStates-1
+   %     for ki=[2*nvar+1:kvar-1]
+   %        Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+   %     end
+   %  end
+end
+
+
+%======== The third equation ===========
+eqninx = 3;
+nreseqn = 1;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0     -1  0  0  0
+      0  1  0  0      0 -1  0  0
+      0  0  1  0      0  0 -1  0
+      0  0  0  1      0  0  0 -1
+
+      0 0 0 0      0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 0 1      0 0 0 0
+
+      0 0 0 0      0 0 0 1
+                         ];
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The fourth equation ===========
+eqninx = 4;
+nreseqn = 0;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0     -1  0  0  0
+      0  1  0  0      0 -1  0  0
+      0  0  1  0      0  0 -1  0
+      0  0  0  1      0  0  0 -1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+
+
+
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+
+for ki=1:nvar   %  initializing loop for each equation
+   Ui{ki} = null(Qi(:,:,ki));
+   Vi{ki} = null(Ri(:,:,ki));
+   n0(ki) = size(Ui{ki},2);
+   np(ki) = size(Vi{ki},2);
+end
diff --git a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol6v.m b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol6v.m
index 4fa71200b8..389109df7a 100644
--- a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol6v.m
+++ b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol6v.m
@@ -1,455 +1,455 @@
-function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol6v(lags,nvar,nStates,indxEqnTv_m,nexo)
-% Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
-%           All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
-%             of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
-%
-% Variables: Pcom, M2, FFR, y, P, U.  Equations: information, policy, money demand, y, P, U.
-% Exporting orthonormal matrices for the deterministic linear restrictions
-%     (equation by equation) with time-varying A0 and D+** equations.
-% See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
-%
-% lags: Maximum length of lag.
-% nvar:  Number of endogeous variables.
-% nStates:  Number of states.
-% indxEqnTv_m: nvar-by-2. Stores equation characteristics.
-%                   1st column: labels of equations [1:nvar]'.
-%                   2nd column: labels of time-varying features with
-%                        1: indxConst -- all coefficients are constant,
-%                        2: indxStv -- only shocks are time-varying,
-%                        3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
-%                        4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
-%                        5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant.
-%          So far this function is written to handle one exogenous variable, which is a constant term.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters
-%           within the state and si is the number of free states.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
-% Vi: nvar-by-1 cell.  In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters within the state and si is the number of free states.
-%           With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
-%           parameters and gi is a vector of free parameters.  The ith equation is in the order of [nvar variables
-%           for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
-%           variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
-% n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
-% np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
-%
-% Tao Zha, February 2003
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
-np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
-
-if (nargin==3)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-end
-
-
-n = nvar*nStates;
-kvar=lags*nvar+nexo;  % Maximum number of lagged and exogenous variables in each equation under each state.
-k = kvar*nStates;  % Maximum number of lagged and exogenous variables in each equation in all states.
-
-Qi = zeros(n,n,nvar);   % 3rd dim: nvar contemporaneous equations.
-Ri = zeros(k,k,nvar);    % 1st and 2nd dims: lagged and exogenous equations.
-   % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
-   %        0 means no restriction.
-   %        1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
-   %        1 (only 1) means that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time for A0_s.
-%-------------------------------------------------------------
-%
-
-%======== The first equation ===========
-eqninx = 1;
-nreseqn = 5;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0     -1  0  0  0  0  0
-      0  1  0  0  0  0      0 -1  0  0  0  0
-      0  0  1  0  0  0      0  0 -1  0  0  0
-      0  0  0  1  0  0      0  0  0 -1  0  0
-      0  0  0  0  1  0      0  0  0  0 -1  0
-      0  0  0  0  0  1      0  0  0  0  0 -1
-
-      0 0 0 0 0 0     0 1 0 0 0 0
-      0 0 0 0 0 0     0 0 1 0 0 0
-      0 0 0 0 0 0     0 0 0 1 0 0
-      0 0 0 0 0 0     0 0 0 0 1 0
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 1 0 0 0 0     0 0 0 0 0 0
-      0 0 1 0 0 0     0 0 0 0 0 0
-      0 0 0 1 0 0     0 0 0 0 0 0
-      0 0 0 0 1 0     0 0 0 0 0 0
-      0 0 0 0 0 1     0 0 0 0 0 0
-
-      0 0 0 0 0 0     0 1 0 0 0 0
-      0 0 0 0 0 0     0 0 1 0 0 0
-      0 0 0 0 0 0     0 0 0 1 0 0
-      0 0 0 0 0 0     0 0 0 0 1 0
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-
-%======== The second equation ===========
-eqninx = 2;
-nreseqn = 4;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0     -1  0  0  0  0  0
-      0  1  0  0  0  0      0 -1  0  0  0  0
-      0  0  1  0  0  0      0  0 -1  0  0  0
-      0  0  0  1  0  0      0  0  0 -1  0  0
-      0  0  0  0  1  0      0  0  0  0 -1  0
-      0  0  0  0  0  1      0  0  0  0  0 -1
-
-      0 0 0 0 0 0     0 0 1 0 0 0
-      0 0 0 0 0 0     0 0 0 1 0 0
-      0 0 0 0 0 0     0 0 0 0 1 0
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 1 0 0 0     0 0 0 0 0 0
-      0 0 0 1 0 0     0 0 0 0 0 0
-      0 0 0 0 1 0     0 0 0 0 0 0
-      0 0 0 0 0 1     0 0 0 0 0 0
-
-      0 0 0 0 0 0     0 0 1 0 0 0
-      0 0 0 0 0 0     0 0 0 1 0 0
-      0 0 0 0 0 0     0 0 0 0 1 0
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The third equation ===========
-eqninx = 3;
-nreseqn = 3;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0     -1  0  0  0  0  0
-      0  1  0  0  0  0      0 -1  0  0  0  0
-      0  0  1  0  0  0      0  0 -1  0  0  0
-      0  0  0  1  0  0      0  0  0 -1  0  0
-      0  0  0  0  1  0      0  0  0  0 -1  0
-      0  0  0  0  0  1      0  0  0  0  0 -1
-
-      0 0 0 0 0 0     0 0 0 1 0 0
-      0 0 0 0 0 0     0 0 0 0 1 0
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 0 1 0 0     0 0 0 0 0 0
-      0 0 0 0 1 0     0 0 0 0 0 0
-      0 0 0 0 0 1     0 0 0 0 0 0
-
-      0 0 0 0 0 0     0 0 0 1 0 0
-      0 0 0 0 0 0     0 0 0 0 1 0
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_3s_case3a.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-
-   %==== For freely time-varying A+ for only the first 6 lags.
-   %====       Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
-   %  nlagsno0 = 6;   % Number of lags to be nonzero.
-   %  for si=1:nStates
-   %     for ki = 1:lags-nlagsno0
-   %        for kj=1:nvar
-   %           Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
-   %        end
-   %     end
-   %  end
-   %**** For constant D+_s except the first two lags and the constant term.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   %  for si=1:nStates-1
-   %     for ki=[2*nvar+1:kvar-1]
-   %        Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-   %     end
-   %  end
-end
-
-
-%======== The fourth equation ===========
-eqninx = 4;
-nreseqn = 2;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0     -1  0  0  0  0  0
-      0  1  0  0  0  0      0 -1  0  0  0  0
-      0  0  1  0  0  0      0  0 -1  0  0  0
-      0  0  0  1  0  0      0  0  0 -1  0  0
-      0  0  0  0  1  0      0  0  0  0 -1  0
-      0  0  0  0  0  1      0  0  0  0  0 -1
-
-      0 0 0 0 0 0     0 0 0 0 1 0
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 0 0 1 0     0 0 0 0 0 0
-      0 0 0 0 0 1     0 0 0 0 0 0
-
-      0 0 0 0 0 0     0 0 0 0 1 0
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The fifth equation ===========
-eqninx = 5;
-nreseqn = 1;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0     -1  0  0  0  0  0
-      0  1  0  0  0  0      0 -1  0  0  0  0
-      0  0  1  0  0  0      0  0 -1  0  0  0
-      0  0  0  1  0  0      0  0  0 -1  0  0
-      0  0  0  0  1  0      0  0  0  0 -1  0
-      0  0  0  0  0  1      0  0  0  0  0 -1
-
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 0 0 0 1     0 0 0 0 0 0
-
-      0 0 0 0 0 0     0 0 0 0 0 1
-                         ];
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The sixth equation ===========
-eqninx = 6;
-nreseqn = 0;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0     -1  0  0  0  0  0
-      0  1  0  0  0  0      0 -1  0  0  0  0
-      0  0  1  0  0  0      0  0 -1  0  0  0
-      0  0  0  1  0  0      0  0  0 -1  0  0
-      0  0  0  0  1  0      0  0  0  0 -1  0
-      0  0  0  0  0  1      0  0  0  0  0 -1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-
-
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-
-for ki=1:nvar   %  initializing loop for each equation
-   Ui{ki} = null(Qi(:,:,ki));
-   Vi{ki} = null(Ri(:,:,ki));
-   n0(ki) = size(Ui{ki},2);
-   np(ki) = size(Vi{ki},2);
-end
+function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol6v(lags,nvar,nStates,indxEqnTv_m,nexo)
+% Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
+%           All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
+%             of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
+%
+% Variables: Pcom, M2, FFR, y, P, U.  Equations: information, policy, money demand, y, P, U.
+% Exporting orthonormal matrices for the deterministic linear restrictions
+%     (equation by equation) with time-varying A0 and D+** equations.
+% See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
+%
+% lags: Maximum length of lag.
+% nvar:  Number of endogeous variables.
+% nStates:  Number of states.
+% indxEqnTv_m: nvar-by-2. Stores equation characteristics.
+%                   1st column: labels of equations [1:nvar]'.
+%                   2nd column: labels of time-varying features with
+%                        1: indxConst -- all coefficients are constant,
+%                        2: indxStv -- only shocks are time-varying,
+%                        3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
+%                        4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
+%                        5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant.
+%          So far this function is written to handle one exogenous variable, which is a constant term.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters
+%           within the state and si is the number of free states.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
+% Vi: nvar-by-1 cell.  In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters within the state and si is the number of free states.
+%           With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
+%           parameters and gi is a vector of free parameters.  The ith equation is in the order of [nvar variables
+%           for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
+%           variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
+% n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
+% np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
+%
+% Tao Zha, February 2003
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
+np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
+
+if (nargin==3)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+end
+
+
+n = nvar*nStates;
+kvar=lags*nvar+nexo;  % Maximum number of lagged and exogenous variables in each equation under each state.
+k = kvar*nStates;  % Maximum number of lagged and exogenous variables in each equation in all states.
+
+Qi = zeros(n,n,nvar);   % 3rd dim: nvar contemporaneous equations.
+Ri = zeros(k,k,nvar);    % 1st and 2nd dims: lagged and exogenous equations.
+   % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
+   %        0 means no restriction.
+   %        1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
+   %        1 (only 1) means that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time for A0_s.
+%-------------------------------------------------------------
+%
+
+%======== The first equation ===========
+eqninx = 1;
+nreseqn = 5;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0     -1  0  0  0  0  0
+      0  1  0  0  0  0      0 -1  0  0  0  0
+      0  0  1  0  0  0      0  0 -1  0  0  0
+      0  0  0  1  0  0      0  0  0 -1  0  0
+      0  0  0  0  1  0      0  0  0  0 -1  0
+      0  0  0  0  0  1      0  0  0  0  0 -1
+
+      0 0 0 0 0 0     0 1 0 0 0 0
+      0 0 0 0 0 0     0 0 1 0 0 0
+      0 0 0 0 0 0     0 0 0 1 0 0
+      0 0 0 0 0 0     0 0 0 0 1 0
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 1 0 0 0 0     0 0 0 0 0 0
+      0 0 1 0 0 0     0 0 0 0 0 0
+      0 0 0 1 0 0     0 0 0 0 0 0
+      0 0 0 0 1 0     0 0 0 0 0 0
+      0 0 0 0 0 1     0 0 0 0 0 0
+
+      0 0 0 0 0 0     0 1 0 0 0 0
+      0 0 0 0 0 0     0 0 1 0 0 0
+      0 0 0 0 0 0     0 0 0 1 0 0
+      0 0 0 0 0 0     0 0 0 0 1 0
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+
+%======== The second equation ===========
+eqninx = 2;
+nreseqn = 4;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0     -1  0  0  0  0  0
+      0  1  0  0  0  0      0 -1  0  0  0  0
+      0  0  1  0  0  0      0  0 -1  0  0  0
+      0  0  0  1  0  0      0  0  0 -1  0  0
+      0  0  0  0  1  0      0  0  0  0 -1  0
+      0  0  0  0  0  1      0  0  0  0  0 -1
+
+      0 0 0 0 0 0     0 0 1 0 0 0
+      0 0 0 0 0 0     0 0 0 1 0 0
+      0 0 0 0 0 0     0 0 0 0 1 0
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 1 0 0 0     0 0 0 0 0 0
+      0 0 0 1 0 0     0 0 0 0 0 0
+      0 0 0 0 1 0     0 0 0 0 0 0
+      0 0 0 0 0 1     0 0 0 0 0 0
+
+      0 0 0 0 0 0     0 0 1 0 0 0
+      0 0 0 0 0 0     0 0 0 1 0 0
+      0 0 0 0 0 0     0 0 0 0 1 0
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The third equation ===========
+eqninx = 3;
+nreseqn = 3;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0     -1  0  0  0  0  0
+      0  1  0  0  0  0      0 -1  0  0  0  0
+      0  0  1  0  0  0      0  0 -1  0  0  0
+      0  0  0  1  0  0      0  0  0 -1  0  0
+      0  0  0  0  1  0      0  0  0  0 -1  0
+      0  0  0  0  0  1      0  0  0  0  0 -1
+
+      0 0 0 0 0 0     0 0 0 1 0 0
+      0 0 0 0 0 0     0 0 0 0 1 0
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 0 1 0 0     0 0 0 0 0 0
+      0 0 0 0 1 0     0 0 0 0 0 0
+      0 0 0 0 0 1     0 0 0 0 0 0
+
+      0 0 0 0 0 0     0 0 0 1 0 0
+      0 0 0 0 0 0     0 0 0 0 1 0
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_3s_case3a.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+
+   %==== For freely time-varying A+ for only the first 6 lags.
+   %====       Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
+   %  nlagsno0 = 6;   % Number of lags to be nonzero.
+   %  for si=1:nStates
+   %     for ki = 1:lags-nlagsno0
+   %        for kj=1:nvar
+   %           Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
+   %        end
+   %     end
+   %  end
+   %**** For constant D+_s except the first two lags and the constant term.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   %  for si=1:nStates-1
+   %     for ki=[2*nvar+1:kvar-1]
+   %        Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+   %     end
+   %  end
+end
+
+
+%======== The fourth equation ===========
+eqninx = 4;
+nreseqn = 2;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0     -1  0  0  0  0  0
+      0  1  0  0  0  0      0 -1  0  0  0  0
+      0  0  1  0  0  0      0  0 -1  0  0  0
+      0  0  0  1  0  0      0  0  0 -1  0  0
+      0  0  0  0  1  0      0  0  0  0 -1  0
+      0  0  0  0  0  1      0  0  0  0  0 -1
+
+      0 0 0 0 0 0     0 0 0 0 1 0
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 0 0 1 0     0 0 0 0 0 0
+      0 0 0 0 0 1     0 0 0 0 0 0
+
+      0 0 0 0 0 0     0 0 0 0 1 0
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The fifth equation ===========
+eqninx = 5;
+nreseqn = 1;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0     -1  0  0  0  0  0
+      0  1  0  0  0  0      0 -1  0  0  0  0
+      0  0  1  0  0  0      0  0 -1  0  0  0
+      0  0  0  1  0  0      0  0  0 -1  0  0
+      0  0  0  0  1  0      0  0  0  0 -1  0
+      0  0  0  0  0  1      0  0  0  0  0 -1
+
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 0 0 0 1     0 0 0 0 0 0
+
+      0 0 0 0 0 0     0 0 0 0 0 1
+                         ];
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The sixth equation ===========
+eqninx = 6;
+nreseqn = 0;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0     -1  0  0  0  0  0
+      0  1  0  0  0  0      0 -1  0  0  0  0
+      0  0  1  0  0  0      0  0 -1  0  0  0
+      0  0  0  1  0  0      0  0  0 -1  0  0
+      0  0  0  0  1  0      0  0  0  0 -1  0
+      0  0  0  0  0  1      0  0  0  0  0 -1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+
+
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+
+for ki=1:nvar   %  initializing loop for each equation
+   Ui{ki} = null(Qi(:,:,ki));
+   Vi{ki} = null(Ri(:,:,ki));
+   n0(ki) = size(Ui{ki},2);
+   np(ki) = size(Vi{ki},2);
+end
diff --git a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol7v.m b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol7v.m
index 6c27034d6c..de818ab905 100644
--- a/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol7v.m
+++ b/tests/ms-sbvar/archive-files/ftd_2s_caseall_upperchol7v.m
@@ -1,525 +1,525 @@
-function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol7v(lags,nvar,nStates,indxEqnTv_m,nexo)
-% Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
-%           All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
-%             of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
-%
-% Variables: Pcom, M2, FFR, y, P, U.  Equations: information, policy, money demand, y, P, U.
-% Exporting orthonormal matrices for the deterministic linear restrictions
-%     (equation by equation) with time-varying A0 and D+** equations.
-% See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
-%
-% lags: Maximum length of lag.
-% nvar:  Number of endogeous variables.
-% nStates:  Number of states.
-% indxEqnTv_m: nvar-by-2. Stores equation characteristics.
-%                   1st column: labels of equations [1:nvar]'.
-%                   2nd column: labels of time-varying features with
-%                        1: indxConst -- all coefficients are constant,
-%                        2: indxStv -- only shocks are time-varying,
-%                        3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
-%                        4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
-%                        5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant.
-%          So far this function is written to handle one exogenous variable, which is a constant term.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters
-%           within the state and si is the number of free states.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
-% Vi: nvar-by-1 cell.  In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters within the state and si is the number of free states.
-%           With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
-%           parameters and gi is a vector of free parameters.  The ith equation is in the order of [nvar variables
-%           for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
-%           variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
-% n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
-% np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
-%
-% Tao Zha, February 2003
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
-np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
-
-if (nargin==3)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-end
-
-
-n = nvar*nStates;
-kvar=lags*nvar+nexo;  % Maximum number of lagged and exogenous variables in each equation under each state.
-k = kvar*nStates;  % Maximum number of lagged and exogenous variables in each equation in all states.
-
-Qi = zeros(n,n,nvar);   % 3rd dim: nvar contemporaneous equations.
-Ri = zeros(k,k,nvar);    % 1st and 2nd dims: lagged and exogenous equations.
-   % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
-   %        0 means no restriction.
-   %        1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
-   %        1 (only 1) means that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time for A0_s.
-%-------------------------------------------------------------
-%
-
-%======== The first equation ===========
-eqninx = 1;
-nreseqn = 6;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
-      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
-      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
-      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
-      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
-      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
-      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
-
-      0 0 0 0 0 0 0       0 1 0 0 0 0 0
-      0 0 0 0 0 0 0       0 0 1 0 0 0 0
-      0 0 0 0 0 0 0       0 0 0 1 0 0 0
-      0 0 0 0 0 0 0       0 0 0 0 1 0 0
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 1 0 0 0 0 0    0 0 0 0 0 0 0
-      0 0 1 0 0 0 0    0 0 0 0 0 0 0
-      0 0 0 1 0 0 0    0 0 0 0 0 0 0
-      0 0 0 0 1 0 0    0 0 0 0 0 0 0
-      0 0 0 0 0 1 0    0 0 0 0 0 0 0
-      0 0 0 0 0 0 1    0 0 0 0 0 0 0
-
-      0 0 0 0 0 0 0       0 1 0 0 0 0 0
-      0 0 0 0 0 0 0       0 0 1 0 0 0 0
-      0 0 0 0 0 0 0       0 0 0 1 0 0 0
-      0 0 0 0 0 0 0       0 0 0 0 1 0 0
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_*.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The second equation ===========
-eqninx = 2;
-nreseqn = 5;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
-      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
-      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
-      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
-      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
-      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
-      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
-
-      0 0 0 0 0 0 0       0 0 1 0 0 0 0
-      0 0 0 0 0 0 0       0 0 0 1 0 0 0
-      0 0 0 0 0 0 0       0 0 0 0 1 0 0
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-       0 0 1 0 0 0 0        0 0 0 0 0 0 0
-       0 0 0 1 0 0 0        0 0 0 0 0 0 0
-       0 0 0 0 1 0 0        0 0 0 0 0 0 0
-       0 0 0 0 0 1 0        0 0 0 0 0 0 0
-       0 0 0 0 0 0 1        0 0 0 0 0 0 0
-
-      0 0 0 0 0 0 0       0 0 1 0 0 0 0
-      0 0 0 0 0 0 0       0 0 0 1 0 0 0
-      0 0 0 0 0 0 0       0 0 0 0 1 0 0
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_*.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The third equation ===========
-eqninx = 3;
-nreseqn = 4;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
-      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
-      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
-      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
-      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
-      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
-      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
-
-      0 0 0 0 0 0 0       0 0 0 1 0 0 0
-      0 0 0 0 0 0 0       0 0 0 0 1 0 0
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 0 1 0 0 0       0 0 0 0 0 0 0
-      0 0 0 0 1 0 0       0 0 0 0 0 0 0
-      0 0 0 0 0 1 0       0 0 0 0 0 0 0
-      0 0 0 0 0 0 1       0 0 0 0 0 0 0
-
-      0 0 0 0 0 0 0       0 0 0 1 0 0 0
-      0 0 0 0 0 0 0       0 0 0 0 1 0 0
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-
-%======== The fourth equation ===========
-eqninx = 4;
-nreseqn = 3;  % Number of linear restrictions for A0(:,eqninx) for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
-      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
-      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
-      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
-      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
-      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
-      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
-
-      0 0 0 0 0 0 0       0 0 0 0 1 0 0
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 0 0 1 0 0       0 0 0 0 0 0 0
-      0 0 0 0 0 1 0       0 0 0 0 0 0 0
-      0 0 0 0 0 0 1       0 0 0 0 0 0 0
-
-      0 0 0 0 0 0 0       0 0 0 0 1 0 0
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_3s_case3a.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-
-   %==== For freely time-varying A+ for only the first 6 lags.
-   %====       Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
-   %  nlagsno0 = 6;   % Number of lags to be nonzero.
-   %  for si=1:nStates
-   %     for ki = 1:lags-nlagsno0
-   %        for kj=1:nvar
-   %           Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
-   %        end
-   %     end
-   %  end
-   %**** For constant D+_s except the first two lags and the constant term.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   %  for si=1:nStates-1
-   %     for ki=[2*nvar+1:kvar-1]
-   %        Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-   %     end
-   %  end
-end
-
-
-%======== The fifth equation ===========
-eqninx = 5;
-nreseqn = 2;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
-      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
-      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
-      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
-      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
-      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
-      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
-
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 0 0 0 1 0        0 0 0 0 0 0 0
-      0 0 0 0 0 0 1        0 0 0 0 0 0 0
-
-      0 0 0 0 0 0 0       0 0 0 0 0 1 0
-      0 0 0 0 0 0 0       0 0 0 0 0 0 1
-                         ];
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The sixth equation ===========
-eqninx = 6;
-nreseqn = 1;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
-      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
-      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
-      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
-      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
-      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
-      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
-
-      0 0 0 0 0 0 0             0 0 0 0 0 0 1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:nreseqn*nStates,:,eqninx) = [
-      0 0 0 0 0 0 1             0 0 0 0 0 0 0
-
-      0 0 0 0 0 0 0             0 0 0 0 0 0 1
-                         ];
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-%======== The seventh equation ===========
-eqninx = 7;
-nreseqn = 0;  % Number of linear restrictions for the equation for each state.
-if (indxEqnTv_m(eqninx, 2)<=2)
-   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
-   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
-      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
-      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
-      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
-      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
-      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
-      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
-      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
-                         ];
-   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   for si=1:nStates-1
-      for ki=1:kvar
-         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-      end
-   end
-else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
-   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
-   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
-      for si=1:nStates-1
-         for ki=1:kvar
-            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
-         end
-      end
-   else
-      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
-   end
-end
-
-
-
-
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-
-for ki=1:nvar   %  initializing loop for each equation
-   Ui{ki} = null(Qi(:,:,ki));
-   Vi{ki} = null(Ri(:,:,ki));
-   n0(ki) = size(Ui{ki},2);
-   np(ki) = size(Vi{ki},2);
-end
+function [Ui,Vi,n0,np] = ftd_2s_caseall_upperchol7v(lags,nvar,nStates,indxEqnTv_m,nexo)
+% Case 2&3: Policy a0j and a+j have only time-varying structural variances -- Case 2.
+%           All policy and nonpolicy a0j's and the corresponding constant terms are completely time-varying and only the scale
+%             of each variable in d+j,1** (excluding the constant term) is time-varying -- Case 3.
+%
+% Variables: Pcom, M2, FFR, y, P, U.  Equations: information, policy, money demand, y, P, U.
+% Exporting orthonormal matrices for the deterministic linear restrictions
+%     (equation by equation) with time-varying A0 and D+** equations.
+% See Model II.3 on pp.71k-71r in TVBVAR NOTES (and Waggoner and Zha's Gibbs sampling paper and TVBVAR NOTES p.58).
+%
+% lags: Maximum length of lag.
+% nvar:  Number of endogeous variables.
+% nStates:  Number of states.
+% indxEqnTv_m: nvar-by-2. Stores equation characteristics.
+%                   1st column: labels of equations [1:nvar]'.
+%                   2nd column: labels of time-varying features with
+%                        1: indxConst -- all coefficients are constant,
+%                        2: indxStv -- only shocks are time-varying,
+%                        3: indxTva0pv -- a0 are freely time-varying and each variable i for d+ is time-varying only by the scale lambda_i(s_t).
+%                        4: indxTva0ps -- a0 are freely time-varying and only the scale for the whole of d+ is time-varying.
+%                        5: indxTv -- time-varying for all coeffficients (a0 and a+) where the lag length for a+ may be shorter.
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant.
+%          So far this function is written to handle one exogenous variable, which is a constant term.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar*nStates-by-qi*si orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters
+%           within the state and si is the number of free states.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation in the order of [a_i for 1st state, ..., a_i for last state].
+% Vi: nvar-by-1 cell.  In each cell, k*nStates-by-ri*si orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters within the state and si is the number of free states.
+%           With this transformation, we have fi = Vi*gi or Vi'*fi = gi where fi is a vector of total original
+%           parameters and gi is a vector of free parameters.  The ith equation is in the order of [nvar variables
+%           for 1st lag and 1st state, ..., nvar variables for last lag and 1st state, const for 1st state, nvar
+%           variables for 1st lag and 2nd state, nvar variables for last lag and 2nd state, const for 2nd state, and so on].
+% n0: nvar-by-1, whose ith element represents the number of free A0 parameters in ith equation in *all states*.
+% np: nvar-by-1, whose ith element represents the number of free D+ parameters in ith equation in *all states*.
+%
+% Tao Zha, February 2003
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation in all states.
+np = zeros(nvar,1); % ith element represents the number of free D+ parameters in ith equation in all states.
+
+if (nargin==3)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+end
+
+
+n = nvar*nStates;
+kvar=lags*nvar+nexo;  % Maximum number of lagged and exogenous variables in each equation under each state.
+k = kvar*nStates;  % Maximum number of lagged and exogenous variables in each equation in all states.
+
+Qi = zeros(n,n,nvar);   % 3rd dim: nvar contemporaneous equations.
+Ri = zeros(k,k,nvar);    % 1st and 2nd dims: lagged and exogenous equations.
+   % Row corresponds to equation with nvar variables for state 1, ..., nvar variables for state nState.
+   %        0 means no restriction.
+   %        1 and -1 or any other number means the linear combination of the corresponding parameters is restricted to 0.
+   %        1 (only 1) means that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time for A0_s.
+%-------------------------------------------------------------
+%
+
+%======== The first equation ===========
+eqninx = 1;
+nreseqn = 6;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
+      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
+      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
+      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
+      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
+      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
+      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
+
+      0 0 0 0 0 0 0       0 1 0 0 0 0 0
+      0 0 0 0 0 0 0       0 0 1 0 0 0 0
+      0 0 0 0 0 0 0       0 0 0 1 0 0 0
+      0 0 0 0 0 0 0       0 0 0 0 1 0 0
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 1 0 0 0 0 0    0 0 0 0 0 0 0
+      0 0 1 0 0 0 0    0 0 0 0 0 0 0
+      0 0 0 1 0 0 0    0 0 0 0 0 0 0
+      0 0 0 0 1 0 0    0 0 0 0 0 0 0
+      0 0 0 0 0 1 0    0 0 0 0 0 0 0
+      0 0 0 0 0 0 1    0 0 0 0 0 0 0
+
+      0 0 0 0 0 0 0       0 1 0 0 0 0 0
+      0 0 0 0 0 0 0       0 0 1 0 0 0 0
+      0 0 0 0 0 0 0       0 0 0 1 0 0 0
+      0 0 0 0 0 0 0       0 0 0 0 1 0 0
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_*.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The second equation ===========
+eqninx = 2;
+nreseqn = 5;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
+      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
+      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
+      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
+      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
+      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
+      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
+
+      0 0 0 0 0 0 0       0 0 1 0 0 0 0
+      0 0 0 0 0 0 0       0 0 0 1 0 0 0
+      0 0 0 0 0 0 0       0 0 0 0 1 0 0
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+       0 0 1 0 0 0 0        0 0 0 0 0 0 0
+       0 0 0 1 0 0 0        0 0 0 0 0 0 0
+       0 0 0 0 1 0 0        0 0 0 0 0 0 0
+       0 0 0 0 0 1 0        0 0 0 0 0 0 0
+       0 0 0 0 0 0 1        0 0 0 0 0 0 0
+
+      0 0 0 0 0 0 0       0 0 1 0 0 0 0
+      0 0 0 0 0 0 0       0 0 0 1 0 0 0
+      0 0 0 0 0 0 0       0 0 0 0 1 0 0
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_*.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The third equation ===========
+eqninx = 3;
+nreseqn = 4;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
+      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
+      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
+      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
+      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
+      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
+      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
+
+      0 0 0 0 0 0 0       0 0 0 1 0 0 0
+      0 0 0 0 0 0 0       0 0 0 0 1 0 0
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 0 1 0 0 0       0 0 0 0 0 0 0
+      0 0 0 0 1 0 0       0 0 0 0 0 0 0
+      0 0 0 0 0 1 0       0 0 0 0 0 0 0
+      0 0 0 0 0 0 1       0 0 0 0 0 0 0
+
+      0 0 0 0 0 0 0       0 0 0 1 0 0 0
+      0 0 0 0 0 0 0       0 0 0 0 1 0 0
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+
+%======== The fourth equation ===========
+eqninx = 4;
+nreseqn = 3;  % Number of linear restrictions for A0(:,eqninx) for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
+      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
+      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
+      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
+      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
+      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
+      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
+
+      0 0 0 0 0 0 0       0 0 0 0 1 0 0
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 0 0 1 0 0       0 0 0 0 0 0 0
+      0 0 0 0 0 1 0       0 0 0 0 0 0 0
+      0 0 0 0 0 0 1       0 0 0 0 0 0 0
+
+      0 0 0 0 0 0 0       0 0 0 0 1 0 0
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_3s_case3a.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+
+   %==== For freely time-varying A+ for only the first 6 lags.
+   %====       Lagged restrictions: zeros on all lags except the first 6 lags in the MS equation.
+   %  nlagsno0 = 6;   % Number of lags to be nonzero.
+   %  for si=1:nStates
+   %     for ki = 1:lags-nlagsno0
+   %        for kj=1:nvar
+   %           Ri(kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,kvar*(si-1)+nlagsno0*nvar+nvar*(ki-1)+kj,2) = 1;
+   %        end
+   %     end
+   %  end
+   %**** For constant D+_s except the first two lags and the constant term.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   %  for si=1:nStates-1
+   %     for ki=[2*nvar+1:kvar-1]
+   %        Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+   %     end
+   %  end
+end
+
+
+%======== The fifth equation ===========
+eqninx = 5;
+nreseqn = 2;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
+      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
+      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
+      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
+      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
+      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
+      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
+
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 0 0 0 1 0        0 0 0 0 0 0 0
+      0 0 0 0 0 0 1        0 0 0 0 0 0 0
+
+      0 0 0 0 0 0 0       0 0 0 0 0 1 0
+      0 0 0 0 0 0 0       0 0 0 0 0 0 1
+                         ];
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The sixth equation ===========
+eqninx = 6;
+nreseqn = 1;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
+      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
+      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
+      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
+      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
+      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
+      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
+
+      0 0 0 0 0 0 0             0 0 0 0 0 0 1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For time-varying A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:nreseqn*nStates,:,eqninx) = [
+      0 0 0 0 0 0 1             0 0 0 0 0 0 0
+
+      0 0 0 0 0 0 0             0 0 0 0 0 0 1
+                         ];
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+%======== The seventh equation ===========
+eqninx = 7;
+nreseqn = 0;  % Number of linear restrictions for the equation for each state.
+if (indxEqnTv_m(eqninx, 2)<=2)
+   %**** For constant A0_s.    In the order of [a0j(1),...,a0j(nStates)] for the 2nd dim of Qi.
+   Qi(1:(nStates-1)*nvar+nreseqn,:,eqninx) = [
+      1  0  0  0  0  0  0     -1  0  0  0  0  0  0
+      0  1  0  0  0  0  0      0 -1  0  0  0  0  0
+      0  0  1  0  0  0  0      0  0 -1  0  0  0  0
+      0  0  0  1  0  0  0      0  0  0 -1  0  0  0
+      0  0  0  0  1  0  0      0  0  0  0 -1  0  0
+      0  0  0  0  0  1  0      0  0  0  0  0 -1  0
+      0  0  0  0  0  0  1      0  0  0  0  0  0 -1
+                         ];
+   %**** For constant D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   for si=1:nStates-1
+      for ki=1:kvar
+         Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+      end
+   end
+else    % Time-varying equations at least for A0_s.  For D+_s, constant-parameter equations in general.
+   %**** For D+_s.  In the order of [aj+(1),...,aj+(nStates)] for the 2nd dim of Ri.
+   if (indxEqnTv_m(eqninx, 2)==3)    % For constant D+** except the constant term.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar-1   % -1: no restrictions on the constant term, which is freely time-varying.
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   elseif (indxEqnTv_m(eqninx, 2)==4)    % For constant D+**.  In the order of [dj**(1),...,dj**(nStates)] for the 2nd dim of Ri.
+      for si=1:nStates-1
+         for ki=1:kvar
+            Ri(kvar*(si-1)+ki,[kvar*(si-1)+ki si*kvar+ki],eqninx) = [1 -1];
+         end
+      end
+   else
+      error('.../ftd_2s_caseall_simszha5v.m:  Have not got time to deal with the simple case indxEqnTv_m(eqninx, 2)=5.')
+   end
+end
+
+
+
+
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+
+for ki=1:nvar   %  initializing loop for each equation
+   Ui{ki} = null(Qi(:,:,ki));
+   Vi{ki} = null(Ri(:,:,ki));
+   n0(ki) = size(Ui{ki},2);
+   np(ki) = size(Vi{ki},2);
+end
diff --git a/tests/ms-sbvar/archive-files/ftd_RSvensson_4v.m b/tests/ms-sbvar/archive-files/ftd_RSvensson_4v.m
index a93ff82b77..2b24a786ab 100644
--- a/tests/ms-sbvar/archive-files/ftd_RSvensson_4v.m
+++ b/tests/ms-sbvar/archive-files/ftd_RSvensson_4v.m
@@ -1,188 +1,188 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_reac_function_4v(lags,nvar,nexo,indxC0Pres)
-%  vlist = [ff+ch fh dpgdp ffr)
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-%   HERE FIRTS 3 EQUATIONS ARE AR2 AND THE LAST EQUATION IS AN UNRESTRICTED
-%   REACTION FUNCTION 2 lags
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-% BN
-
-nvar=4;
-lags=4;
-nexo=1;
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%
-%======== The first equation ===========
-Qi(1:3,:,1) = [
-    0 1 0 0
-    0 0 1 0
-    0 0 0 1
-        ];
-
-%======== The second equation ===========
-Qi(1:2,:,2) = [
-    0 0 1 0
-    0 0 0 1
-        ];
-
-%======== The third equation =========== NOTE THAT WE FORBID A
-%CONTEMPORANEOUS IMPACT OF OUTPUTON PRICES TO AVOID A CONSTRAINT THAT
-%INVOLVE A0 and Aplus
-Qi(1:3,:,3) = [
-    1 0 0 0
-    0 1 0 0
-    0 0 0 1
-        ];
-
-%======== The fourth equation ===========
-
-
-% Restrictions on the A+ in order to focus strictly on the reaction fucntion
-
-% indicates free parameterers X i
-%	Ap = [
-%      X  X    X  X
-%	   X  X    X  X
-%     -a1 -b1  X  X
-%      a1 b1   0  X  (1st lag)
-%      X  X    X  X
-%	   X  X    X  X
-%     -a2 -b2  X  X
-%      b2  b2  0  X  (2nd lag)
-%      X   0   X  X
-%	   X  X    X  X
-%     -a3 -b3  X  X
-%      a3  a3  0  X  (3rd lag)
-%      X  X    X  X
-%	   X  X    X  X
-%     -a4 -b4  X  X
-%      a4  b4  0  X  (4th lag)
-%      X  X    X  X  (constant terms)
-%			  ];
-
-k=nvar*lags+nexo;
-Ri = zeros(k,k,nvar);
-% constraints on IS curve /conso+corporate investment
-for nv=1:2
-for ll=1:lags
-Ri(ll,3+lags*(ll-1),nv)=1;
-Ri(ll,4+lags*(ll-1),nv)=1;
-end
-end
-
-% constraints on IS curve /conso+corporate investment only on the long run
-% impact
-% for nv=1:2
-% for ll=1:lags
-% Ri(1,3+lags*(ll-1),nv)=1;
-% Ri(1,4+lags*(ll-1),nv)=1;
-% end
-% end
-
-
-% constraints on Ph curve / inflation does not react to interest rates
-for ll=1:lags
-Ri(ll,4+lags*(ll-1),3)=1;
-end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_reac_function_4v(lags,nvar,nexo,indxC0Pres)
+%  vlist = [ff+ch fh dpgdp ffr)
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+%   HERE FIRTS 3 EQUATIONS ARE AR2 AND THE LAST EQUATION IS AN UNRESTRICTED
+%   REACTION FUNCTION 2 lags
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+% BN
+
+nvar=4;
+lags=4;
+nexo=1;
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%
+%======== The first equation ===========
+Qi(1:3,:,1) = [
+    0 1 0 0
+    0 0 1 0
+    0 0 0 1
+        ];
+
+%======== The second equation ===========
+Qi(1:2,:,2) = [
+    0 0 1 0
+    0 0 0 1
+        ];
+
+%======== The third equation =========== NOTE THAT WE FORBID A
+%CONTEMPORANEOUS IMPACT OF OUTPUTON PRICES TO AVOID A CONSTRAINT THAT
+%INVOLVE A0 and Aplus
+Qi(1:3,:,3) = [
+    1 0 0 0
+    0 1 0 0
+    0 0 0 1
+        ];
+
+%======== The fourth equation ===========
+
+
+% Restrictions on the A+ in order to focus strictly on the reaction fucntion
+
+% indicates free parameterers X i
+%	Ap = [
+%      X  X    X  X
+%	   X  X    X  X
+%     -a1 -b1  X  X
+%      a1 b1   0  X  (1st lag)
+%      X  X    X  X
+%	   X  X    X  X
+%     -a2 -b2  X  X
+%      b2  b2  0  X  (2nd lag)
+%      X   0   X  X
+%	   X  X    X  X
+%     -a3 -b3  X  X
+%      a3  a3  0  X  (3rd lag)
+%      X  X    X  X
+%	   X  X    X  X
+%     -a4 -b4  X  X
+%      a4  b4  0  X  (4th lag)
+%      X  X    X  X  (constant terms)
+%			  ];
+
+k=nvar*lags+nexo;
+Ri = zeros(k,k,nvar);
+% constraints on IS curve /conso+corporate investment
+for nv=1:2
+for ll=1:lags
+Ri(ll,3+lags*(ll-1),nv)=1;
+Ri(ll,4+lags*(ll-1),nv)=1;
+end
+end
+
+% constraints on IS curve /conso+corporate investment only on the long run
+% impact
+% for nv=1:2
+% for ll=1:lags
+% Ri(1,3+lags*(ll-1),nv)=1;
+% Ri(1,4+lags*(ll-1),nv)=1;
+% end
+% end
+
+
+% constraints on Ph curve / inflation does not react to interest rates
+for ll=1:lags
+Ri(ll,4+lags*(ll-1),3)=1;
+end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/ms-sbvar/archive-files/ftd_cholesky.m b/tests/ms-sbvar/archive-files/ftd_cholesky.m
index 74524c4701..42126015ab 100644
--- a/tests/ms-sbvar/archive-files/ftd_cholesky.m
+++ b/tests/ms-sbvar/archive-files/ftd_cholesky.m
@@ -1,251 +1,251 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_cholesky(lags,nvar,nexo,indxC0Pres)
-%vlist = [1:4];    % regarding "xdd", % 1: p; 2: id; 3: ik; 4: y.
-%For restricted VARs in the form: y_t'*A0 = x_t'*Ap + e_t', where y_t is a vector of endogenous variables
-%      and x_t is a vector of lagged endogenous variables and the constant term (last term).
-%      Note that the columns of A0 and Ap correspnd to equations.
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%The restrictions considered here are in the following form where X means unrestricted:
-%  A0 = [
-%      X  0  X  X
-%		 0  X  X  X
-%		 0  0  X  X
-%		 0  0  0  X
-%			];
-%	Ap = [
-%      X  0  X  X
-%		 0  X  X  X
-%      0  0  X  X
-%      0  0  X  X  (1st lag)
-%      X  0  X  X
-%		 0  X  X  X
-%      0  0  X  X
-%      0  0  X  X  (2nd lag)
-%      X  0  X  X
-%		 0  X  X  X
-%      0  0  X  X
-%      0  0  X  X  (3rd lag)
-%      X  0  X  X
-%		 0  X  X  X
-%      0  0  X  X
-%      0  0  X  X  (4th lag)
-%      0  X  0  0  (constant terms)
-%			];
-
-if (0)
-	%------------------------ Lower triangular A0 ------------------------------
-	%======== The first equation ===========
-
-
-	%======== The second equation ===========
-	Qi(1:1,:,2) = [
-	   1 0 0 0
-	        ];
-
-	%======== The third equation ===========
-	Qi(1:2,:,3) = [
-	   1 0 0 0
-	   0 1 0 0
-	        ];
-
-	%======== The fourth equation ===========
-	Qi(1:3,:,4) = [
-	   1 0 0 0
-	   0 1 0 0
-	   0 0 1 0
-	        ];
-else
-	%------------------------ Upper triangular A0 ------------------------------
-	%======== The first equation ===========
-	Qi(2:4,:,1) = [
-	   0 1 0 0
-	   0 0 1 0
-	   0 0 0 1
-	        ];
-
-	%======== The second equation ===========
-   Qi([1 3:4],:,2) = [
-      1 0 0 0
-      0 0 1 0
-	   0 0 0 1
-	        ];
-
-	%======== The third equation ===========
-	Qi(4:4,:,3) = [
-	   0 0 0 1
-	        ];
-
-	%======== The fourth equation ===========
-end
-
-
-%-------------------------- Lag restrictions. ------------------------------------------
-if (1)
-	%--- Lag restrictions.
-	indxeqn = 1;   %Which equation.
-	nrestrs = (nvar-1)*lags+1;  %Number of restrictions.
-	vars_restr = [2:nvar];  %Variables that are restricted:  id, ik, and y.
-   blags = zeros(nrestrs,k);  %k=nvar*lags+1
-	cnt = 0;
-	for ki = 1:lags
-	   for kj=vars_restr
-	      cnt = cnt+1;
-	      blags(cnt,nvar*(ki-1)+kj) = 1;
-	   end
-	end
-	%--- Keep constant zero.
-	cnt = cnt+1;
-	blags(cnt,end) = 1;  %Constant = 0.
-	if cnt~=nrestrs
-	   error('Check lagged restrictions in 1st equation!')
-	end
-	Ri(1:nrestrs,:,indxeqn) = blags;
-
-	%--- Lag restrictions.
-	indxeqn = 2;   %Which equation.
-   nrestrs = (nvar-1)*lags;  %Number of restrictions.
-   vars_restr = [1 3:nvar];  %Variables that are restricted:  id, ik, and y.
-   blags = zeros(nrestrs,k);  %k=nvar*lags+1
-   cnt = 0;
-   for ki = 1:lags
-      for kj=vars_restr
-         cnt = cnt+1;
-         blags(cnt,nvar*(ki-1)+kj) = 1;
-      end
-   end
-	Ri(1:nrestrs,:,indxeqn) = blags;
-
-	%--- Lag restrictions.
-	indxeqn = 3;   %Which equation.
-	nrestrs = 1;  %Number of restrictions.
-	blags = zeros(nrestrs,k);
-	cnt = 0;
-	%--- Keep constant zero.
-	cnt = cnt+1;
-	blags(cnt,end) = 1;  %Constant = 0.
-	if cnt~=nrestrs
-	   error('Check lagged restrictions in 1st equation!')
-	end
-	Ri(1:nrestrs,:,indxeqn) = blags;
-
-	%--- Lag restrictions.
-	indxeqn = 4;   %Which equation.
-	nrestrs = 1;  %Number of restrictions.
-	blags = zeros(nrestrs,k);
-	cnt = 0;
-	%--- Keep constant zero.
-	cnt = cnt+1;
-	blags(cnt,end) = 1;  %Constant = 0.
-	if cnt~=nrestrs
-	   error('Check lagged restrictions in 1st equation!')
-	end
-	Ri(1:nrestrs,:,indxeqn) = blags;
-end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%  This type of restriction is used for the New-Keysian model studied by Leeper and Zha
-%    "Assessing Simple Policy Rules: A View from a Complete Macroeconomic Model" published
-%    by St. Louis Fed Review.
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_cholesky(lags,nvar,nexo,indxC0Pres)
+%vlist = [1:4];    % regarding "xdd", % 1: p; 2: id; 3: ik; 4: y.
+%For restricted VARs in the form: y_t'*A0 = x_t'*Ap + e_t', where y_t is a vector of endogenous variables
+%      and x_t is a vector of lagged endogenous variables and the constant term (last term).
+%      Note that the columns of A0 and Ap correspnd to equations.
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%The restrictions considered here are in the following form where X means unrestricted:
+%  A0 = [
+%      X  0  X  X
+%		 0  X  X  X
+%		 0  0  X  X
+%		 0  0  0  X
+%			];
+%	Ap = [
+%      X  0  X  X
+%		 0  X  X  X
+%      0  0  X  X
+%      0  0  X  X  (1st lag)
+%      X  0  X  X
+%		 0  X  X  X
+%      0  0  X  X
+%      0  0  X  X  (2nd lag)
+%      X  0  X  X
+%		 0  X  X  X
+%      0  0  X  X
+%      0  0  X  X  (3rd lag)
+%      X  0  X  X
+%		 0  X  X  X
+%      0  0  X  X
+%      0  0  X  X  (4th lag)
+%      0  X  0  0  (constant terms)
+%			];
+
+if (0)
+	%------------------------ Lower triangular A0 ------------------------------
+	%======== The first equation ===========
+
+
+	%======== The second equation ===========
+	Qi(1:1,:,2) = [
+	   1 0 0 0
+	        ];
+
+	%======== The third equation ===========
+	Qi(1:2,:,3) = [
+	   1 0 0 0
+	   0 1 0 0
+	        ];
+
+	%======== The fourth equation ===========
+	Qi(1:3,:,4) = [
+	   1 0 0 0
+	   0 1 0 0
+	   0 0 1 0
+	        ];
+else
+	%------------------------ Upper triangular A0 ------------------------------
+	%======== The first equation ===========
+	Qi(2:4,:,1) = [
+	   0 1 0 0
+	   0 0 1 0
+	   0 0 0 1
+	        ];
+
+	%======== The second equation ===========
+   Qi([1 3:4],:,2) = [
+      1 0 0 0
+      0 0 1 0
+	   0 0 0 1
+	        ];
+
+	%======== The third equation ===========
+	Qi(4:4,:,3) = [
+	   0 0 0 1
+	        ];
+
+	%======== The fourth equation ===========
+end
+
+
+%-------------------------- Lag restrictions. ------------------------------------------
+if (1)
+	%--- Lag restrictions.
+	indxeqn = 1;   %Which equation.
+	nrestrs = (nvar-1)*lags+1;  %Number of restrictions.
+	vars_restr = [2:nvar];  %Variables that are restricted:  id, ik, and y.
+   blags = zeros(nrestrs,k);  %k=nvar*lags+1
+	cnt = 0;
+	for ki = 1:lags
+	   for kj=vars_restr
+	      cnt = cnt+1;
+	      blags(cnt,nvar*(ki-1)+kj) = 1;
+	   end
+	end
+	%--- Keep constant zero.
+	cnt = cnt+1;
+	blags(cnt,end) = 1;  %Constant = 0.
+	if cnt~=nrestrs
+	   error('Check lagged restrictions in 1st equation!')
+	end
+	Ri(1:nrestrs,:,indxeqn) = blags;
+
+	%--- Lag restrictions.
+	indxeqn = 2;   %Which equation.
+   nrestrs = (nvar-1)*lags;  %Number of restrictions.
+   vars_restr = [1 3:nvar];  %Variables that are restricted:  id, ik, and y.
+   blags = zeros(nrestrs,k);  %k=nvar*lags+1
+   cnt = 0;
+   for ki = 1:lags
+      for kj=vars_restr
+         cnt = cnt+1;
+         blags(cnt,nvar*(ki-1)+kj) = 1;
+      end
+   end
+	Ri(1:nrestrs,:,indxeqn) = blags;
+
+	%--- Lag restrictions.
+	indxeqn = 3;   %Which equation.
+	nrestrs = 1;  %Number of restrictions.
+	blags = zeros(nrestrs,k);
+	cnt = 0;
+	%--- Keep constant zero.
+	cnt = cnt+1;
+	blags(cnt,end) = 1;  %Constant = 0.
+	if cnt~=nrestrs
+	   error('Check lagged restrictions in 1st equation!')
+	end
+	Ri(1:nrestrs,:,indxeqn) = blags;
+
+	%--- Lag restrictions.
+	indxeqn = 4;   %Which equation.
+	nrestrs = 1;  %Number of restrictions.
+	blags = zeros(nrestrs,k);
+	cnt = 0;
+	%--- Keep constant zero.
+	cnt = cnt+1;
+	blags(cnt,end) = 1;  %Constant = 0.
+	if cnt~=nrestrs
+	   error('Check lagged restrictions in 1st equation!')
+	end
+	Ri(1:nrestrs,:,indxeqn) = blags;
+end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%  This type of restriction is used for the New-Keysian model studied by Leeper and Zha
+%    "Assessing Simple Policy Rules: A View from a Complete Macroeconomic Model" published
+%    by St. Louis Fed Review.
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/ms-sbvar/archive-files/ftd_non_rec_5v.m b/tests/ms-sbvar/archive-files/ftd_non_rec_5v.m
index e7ae075494..e9fbeb4099 100644
--- a/tests/ms-sbvar/archive-files/ftd_non_rec_5v.m
+++ b/tests/ms-sbvar/archive-files/ftd_non_rec_5v.m
@@ -1,192 +1,192 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol5v(lags,nvar,nexo,indxC0Pres)
-%  vlist = [127 124 93 141 21];    % 1: GDP; 2: GDP deflator 124 (consumption deflator 79); 3: R; 4: M3 141 (M2 140); 5: exchange rate 21.
-%  varlist={'y', 'P', 'R', 'M3', 'Ex'};
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%
-%======== The first equation ===========
-Qi(1:4,:,1) = [
-    0 1 0 0 0
-    0 0 1 0 0
-    0 0 0 1 0
-    0 0 0 0 1
-        ];
-
-%======== The second equation ===========
-Qi(1:3,:,2) = [
-    0 0 1 0 0
-    0 0 0 1 0
-    0 0 0 0 1
-        ];
-
-%======== The third equation ===========
-Qi(1:2,:,3) = [
-    0 0 0 1 0
-    0 0 0 0 1
-        ];
-
-
-%======== The fourth equation ===========
-%Qi(1:1,:,4) = [
-%    0 0 0 0 1
-%         ];
-
-
-%======== The fifth equation ===========
-
-Qi(1:3,:,5) = [
-    1 0 0 0 0
-    0 1 0 0 0
-    0 0 1 0 0
-         ];
-
-
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol5v(lags,nvar,nexo,indxC0Pres)
+%  vlist = [127 124 93 141 21];    % 1: GDP; 2: GDP deflator 124 (consumption deflator 79); 3: R; 4: M3 141 (M2 140); 5: exchange rate 21.
+%  varlist={'y', 'P', 'R', 'M3', 'Ex'};
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%
+%======== The first equation ===========
+Qi(1:4,:,1) = [
+    0 1 0 0 0
+    0 0 1 0 0
+    0 0 0 1 0
+    0 0 0 0 1
+        ];
+
+%======== The second equation ===========
+Qi(1:3,:,2) = [
+    0 0 1 0 0
+    0 0 0 1 0
+    0 0 0 0 1
+        ];
+
+%======== The third equation ===========
+Qi(1:2,:,3) = [
+    0 0 0 1 0
+    0 0 0 0 1
+        ];
+
+
+%======== The fourth equation ===========
+%Qi(1:1,:,4) = [
+%    0 0 0 0 1
+%         ];
+
+
+%======== The fifth equation ===========
+
+Qi(1:3,:,5) = [
+    1 0 0 0 0
+    0 1 0 0 0
+    0 0 1 0 0
+         ];
+
+
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/ms-sbvar/archive-files/ftd_simszha5v.m b/tests/ms-sbvar/archive-files/ftd_simszha5v.m
index a2092fb3e8..0a0034a9d0 100644
--- a/tests/ms-sbvar/archive-files/ftd_simszha5v.m
+++ b/tests/ms-sbvar/archive-files/ftd_simszha5v.m
@@ -1,190 +1,190 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_simszha5v(lags,nvar,nexo,indxC0Pres)
-%vlist = [21  141  93  127  124];    % 1: Pcom 2 (exchange rate 21); 2: M3 141 (M2 140); 3: R; 4: GDP; 5: GDP deflator 124 (consumption deflator 79).
-%varlist={'Ex', 'M3', 'R', 'y','P'};
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%
-
-%======== The first equation: information sector ===========
-
-
-%======== The second equation: monetary policy ===========
-%Qi(1:2,:,2) = [
-%   0 0 0 1 0
-%   0 0 0 0 1
-%        ];    % Respond to Pcom.
-Qi(1:3,:,2) = [
-   1 0 0 0 0
-   0 0 0 1 0
-   0 0 0 0 1
-        ];    % Not respond to Pcom.
-
-%======== The third equation: money demand ===========
-Qi(1,:,3) = [
-   1 0 0 0 0
-        ];
-
-%======== The fourth equation: y equation ===========
-Qi(1:4,:,4) = [
-   1 0 0 0 0
-   0 1 0 0 0
-   0 0 1 0 0
-   0 0 0 0 1
-        ];
-
-%======== The fifth equation: p equation ===========
-Qi(1:3,:,5) = [
-   1 0 0 0 0
-   0 1 0 0 0
-   0 0 1 0 0
-        ];
-
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_simszha5v(lags,nvar,nexo,indxC0Pres)
+%vlist = [21  141  93  127  124];    % 1: Pcom 2 (exchange rate 21); 2: M3 141 (M2 140); 3: R; 4: GDP; 5: GDP deflator 124 (consumption deflator 79).
+%varlist={'Ex', 'M3', 'R', 'y','P'};
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%
+
+%======== The first equation: information sector ===========
+
+
+%======== The second equation: monetary policy ===========
+%Qi(1:2,:,2) = [
+%   0 0 0 1 0
+%   0 0 0 0 1
+%        ];    % Respond to Pcom.
+Qi(1:3,:,2) = [
+   1 0 0 0 0
+   0 0 0 1 0
+   0 0 0 0 1
+        ];    % Not respond to Pcom.
+
+%======== The third equation: money demand ===========
+Qi(1,:,3) = [
+   1 0 0 0 0
+        ];
+
+%======== The fourth equation: y equation ===========
+Qi(1:4,:,4) = [
+   1 0 0 0 0
+   0 1 0 0 0
+   0 0 1 0 0
+   0 0 0 0 1
+        ];
+
+%======== The fifth equation: p equation ===========
+Qi(1:3,:,5) = [
+   1 0 0 0 0
+   0 1 0 0 0
+   0 0 1 0 0
+        ];
+
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol3v.m b/tests/ms-sbvar/archive-files/ftd_upperchol3v.m
index 4376b3c5d5..a5c19f79e8 100644
--- a/tests/ms-sbvar/archive-files/ftd_upperchol3v.m
+++ b/tests/ms-sbvar/archive-files/ftd_upperchol3v.m
@@ -1,170 +1,170 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol3v(lags,nvar,nexo,indxC0Pres)
-%vlist = [20 6 3 44 1 10];    % regarding "xdd", Pcom (Poil or imfcom), M2, FFR, GDP, CPI (or PCE), and U.
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%
-
-%======== The first equation ===========
-Qi(1:2,:,1) = [
-    0 1 0
-    0 0 1
-        ];
-
-%======== The second equation ===========
-Qi(1:1,:,2) = [
-    0 0 1
-        ];
-
-
-%======== The third equation ===========
-
-
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol3v(lags,nvar,nexo,indxC0Pres)
+%vlist = [20 6 3 44 1 10];    % regarding "xdd", Pcom (Poil or imfcom), M2, FFR, GDP, CPI (or PCE), and U.
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%
+
+%======== The first equation ===========
+Qi(1:2,:,1) = [
+    0 1 0
+    0 0 1
+        ];
+
+%======== The second equation ===========
+Qi(1:1,:,2) = [
+    0 0 1
+        ];
+
+
+%======== The third equation ===========
+
+
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol4v.m b/tests/ms-sbvar/archive-files/ftd_upperchol4v.m
index 78c9a7c514..aadac9512f 100644
--- a/tests/ms-sbvar/archive-files/ftd_upperchol4v.m
+++ b/tests/ms-sbvar/archive-files/ftd_upperchol4v.m
@@ -1,178 +1,178 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol4v(lags,nvar,nexo,indxC0Pres)
-%  vlist = [127 124 93 141 21];    % 1: GDP; 2: GDP deflator 124 (consumption deflator 79); 3: R; 4: M3 141 (M2 140); 5: exchange rate 21.
-%  varlist={'y', 'P', 'R', 'M3', 'Ex'};
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%
-%======== The first equation ===========
-Qi(1:3,:,1) = [
-    0 1 0 0
-    0 0 1 0
-    0 0 0 1
-        ];
-
-%======== The second equation ===========
-Qi(1:2,:,2) = [
-    0 0 1 0
-    0 0 0 1
-        ];
-
-%======== The third equation ===========
-Qi(1:1,:,3) = [
-    0 0 0 1
-        ];
-
-
-%======== The fourth equation ===========
-
-
-
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol4v(lags,nvar,nexo,indxC0Pres)
+%  vlist = [127 124 93 141 21];    % 1: GDP; 2: GDP deflator 124 (consumption deflator 79); 3: R; 4: M3 141 (M2 140); 5: exchange rate 21.
+%  varlist={'y', 'P', 'R', 'M3', 'Ex'};
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%
+%======== The first equation ===========
+Qi(1:3,:,1) = [
+    0 1 0 0
+    0 0 1 0
+    0 0 0 1
+        ];
+
+%======== The second equation ===========
+Qi(1:2,:,2) = [
+    0 0 1 0
+    0 0 0 1
+        ];
+
+%======== The third equation ===========
+Qi(1:1,:,3) = [
+    0 0 0 1
+        ];
+
+
+%======== The fourth equation ===========
+
+
+
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol5v.m b/tests/ms-sbvar/archive-files/ftd_upperchol5v.m
index e1dfaa18d5..b41a60c174 100644
--- a/tests/ms-sbvar/archive-files/ftd_upperchol5v.m
+++ b/tests/ms-sbvar/archive-files/ftd_upperchol5v.m
@@ -1,187 +1,187 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol5v(lags,nvar,nexo,indxC0Pres)
-%  vlist = [127 124 93 141 21];    % 1: GDP; 2: GDP deflator 124 (consumption deflator 79); 3: R; 4: M3 141 (M2 140); 5: exchange rate 21.
-%  varlist={'y', 'P', 'R', 'M3', 'Ex'};
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%
-%======== The first equation ===========
-Qi(1:4,:,1) = [
-    0 1 0 0 0
-    0 0 1 0 0
-    0 0 0 1 0
-    0 0 0 0 1
-        ];
-
-%======== The second equation ===========
-Qi(1:3,:,2) = [
-    0 0 1 0 0
-    0 0 0 1 0
-    0 0 0 0 1
-        ];
-
-%======== The third equation ===========
-Qi(1:2,:,3) = [
-    0 0 0 1 0
-    0 0 0 0 1
-        ];
-
-
-%======== The fourth equation ===========
-Qi(1:1,:,4) = [
-    0 0 0 0 1
-         ];
-
-
-%======== The fifth equation ===========
-
-
-
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol5v(lags,nvar,nexo,indxC0Pres)
+%  vlist = [127 124 93 141 21];    % 1: GDP; 2: GDP deflator 124 (consumption deflator 79); 3: R; 4: M3 141 (M2 140); 5: exchange rate 21.
+%  varlist={'y', 'P', 'R', 'M3', 'Ex'};
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%
+%======== The first equation ===========
+Qi(1:4,:,1) = [
+    0 1 0 0 0
+    0 0 1 0 0
+    0 0 0 1 0
+    0 0 0 0 1
+        ];
+
+%======== The second equation ===========
+Qi(1:3,:,2) = [
+    0 0 1 0 0
+    0 0 0 1 0
+    0 0 0 0 1
+        ];
+
+%======== The third equation ===========
+Qi(1:2,:,3) = [
+    0 0 0 1 0
+    0 0 0 0 1
+        ];
+
+
+%======== The fourth equation ===========
+Qi(1:1,:,4) = [
+    0 0 0 0 1
+         ];
+
+
+%======== The fifth equation ===========
+
+
+
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol6v.m b/tests/ms-sbvar/archive-files/ftd_upperchol6v.m
index fb09e9298f..c6560ffd98 100644
--- a/tests/ms-sbvar/archive-files/ftd_upperchol6v.m
+++ b/tests/ms-sbvar/archive-files/ftd_upperchol6v.m
@@ -1,194 +1,194 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol6v(lags,nvar,nexo,indxC0Pres)
-%  vlist = [127 124 2 93 141 21];    % 1: Pcom 2 (exchange rate 21); 2: M3 141 (M2 140); 3: R; 4: GDP; 5: GDP deflator 124 (consumption deflator 79).
-%  varlist={'y', 'P', 'Pcom', 'R', 'M3', 'Ex'};
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%
-%======== The first equation ===========
-Qi(1:5,:,1) = [
-    0 1 0 0 0 0
-    0 0 1 0 0 0
-    0 0 0 1 0 0
-    0 0 0 0 1 0
-    0 0 0 0 0 1
-        ];
-
-%======== The second equation ===========
-Qi(1:4,:,2) = [
-    0 0 1 0 0 0
-    0 0 0 1 0 0
-    0 0 0 0 1 0
-    0 0 0 0 0 1
-        ];
-
-%======== The third equation ===========
-Qi(1:3,:,3) = [
-    0 0 0 1 0 0
-    0 0 0 0 1 0
-    0 0 0 0 0 1
-        ];
-
-
-%======== The fourth equation ===========
-Qi(1:2,:,4) = [
-    0 0 0 0 1 0
-    0 0 0 0 0 1
-         ];
-
-
-%======== The fifth equation ===========
-Qi(1:1,:,5) = [
-    0 0 0 0 0 1
-         ];
-
-
-%======== The sixth equation ===========
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol6v(lags,nvar,nexo,indxC0Pres)
+%  vlist = [127 124 2 93 141 21];    % 1: Pcom 2 (exchange rate 21); 2: M3 141 (M2 140); 3: R; 4: GDP; 5: GDP deflator 124 (consumption deflator 79).
+%  varlist={'y', 'P', 'Pcom', 'R', 'M3', 'Ex'};
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%
+%======== The first equation ===========
+Qi(1:5,:,1) = [
+    0 1 0 0 0 0
+    0 0 1 0 0 0
+    0 0 0 1 0 0
+    0 0 0 0 1 0
+    0 0 0 0 0 1
+        ];
+
+%======== The second equation ===========
+Qi(1:4,:,2) = [
+    0 0 1 0 0 0
+    0 0 0 1 0 0
+    0 0 0 0 1 0
+    0 0 0 0 0 1
+        ];
+
+%======== The third equation ===========
+Qi(1:3,:,3) = [
+    0 0 0 1 0 0
+    0 0 0 0 1 0
+    0 0 0 0 0 1
+        ];
+
+
+%======== The fourth equation ===========
+Qi(1:2,:,4) = [
+    0 0 0 0 1 0
+    0 0 0 0 0 1
+         ];
+
+
+%======== The fifth equation ===========
+Qi(1:1,:,5) = [
+    0 0 0 0 0 1
+         ];
+
+
+%======== The sixth equation ===========
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/ms-sbvar/archive-files/ftd_upperchol7v.m b/tests/ms-sbvar/archive-files/ftd_upperchol7v.m
index 31ce836cf0..d0dc7969c4 100644
--- a/tests/ms-sbvar/archive-files/ftd_upperchol7v.m
+++ b/tests/ms-sbvar/archive-files/ftd_upperchol7v.m
@@ -1,204 +1,204 @@
-function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol7v(lags,nvar,nexo,indxC0Pres)
-%  vlist = [127 124 2 93 141 21];    % 1: Pcom 2 (exchange rate 21); 2: M3 141 (M2 140); 3: R; 4: GDP; 5: GDP deflator 124 (consumption deflator 79).
-%  varlist={'y', 'P', 'Pcom', 'R', 'M3', 'Ex'};
-%
-%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
-%    See Waggoner and Zha's Gibbs sampling paper.
-%
-% q_m:  quarter or month
-% lags: the maximum length of lag
-% nvar:  number of endogeous variables
-% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
-% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
-%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
-%                These restrictions have to be manually and carefully keyed in.
-%-----------------
-% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
-%           equation contemporaneous restriction matrix where qi is the number of free parameters.
-%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
-%           of total original parameters and bi is a vector of free parameters. When no
-%           restrictions are imposed, we have Ui = I.  There must be at least one free
-%           parameter left for the ith equation.
-% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
-%           equation lagged restriction matrix where k is a total of exogenous variables and
-%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
-%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
-%           vector of free parameters. There must be at least one free parameter left for
-%           the ith equation.
-% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
-% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
-% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
-%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
-%             In the jth cell representing equation, we have 4 columns:
-%               1st: the jth column (equation) of A+ or A0: f_j or a_j
-%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%               4th: the number s such that f_j(i) = s * a_j(h) holds.
-%
-% Tao Zha, May 2000
-
-
-
-Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
-Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
-n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
-np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
-
-if (nargin==2)
-   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
-elseif (nargin==3)
-   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
-end
-
-k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
-
-Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
-Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
-  % Row corresponds to equation. 0 means no restriction.
-  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
-
-%nfvar = 6;   % number of foreign (Granger causing) variables
-%nhvar = nvar-nfvar;  % number of home (affected) variables.
-
-
-%-------------------------------------------------------------
-%  Beginning the manual input of the restrictions one quation at a time
-%-------------------------------------------------------------
-%
-%======== The first equation ===========
-Qi(1:6,:,1) = [
-    0 1 0 0 0 0 0
-    0 0 1 0 0 0 0
-    0 0 0 1 0 0 0
-    0 0 0 0 1 0 0
-    0 0 0 0 0 1 0
-    0 0 0 0 0 0 1
-        ];
-
-%======== The second equation ===========
-Qi(1:5,:,2) = [
-    0 0 1 0 0 0 0
-    0 0 0 1 0 0 0
-    0 0 0 0 1 0 0
-    0 0 0 0 0 1 0
-    0 0 0 0 0 0 1
-        ];
-
-%======== The third equation ===========
-Qi(1:4,:,3) = [
-    0 0 0 1 0 0 0
-    0 0 0 0 1 0 0
-    0 0 0 0 0 1 0
-    0 0 0 0 0 0 1
-        ];
-
-%======== The fourth equation ===========
-Qi(1:3,:,4) = [
-    0 0 0 0 1 0 0
-    0 0 0 0 0 1 0
-    0 0 0 0 0 0 1
-        ];
-
-
-%======== The fifth equation ===========
-Qi(1:2,:,5) = [
-    0 0 0 0 0 1 0
-    0 0 0 0 0 0 1
-         ];
-
-
-%======== The sixth equation ===========
-Qi(1:1,:,6) = [
-    0 0 0 0 0 0 1
-         ];
-
-
-%======== The seventh equation ===========
-
-%===== Lagged restrictions in foreign (Granger causing) block
-%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
-%bfor = zeros(nfbres,k);  % each foreign equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:nvar-nfvar
-%      cnt=cnt+1;
-%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
-%   end
-%end
-%%
-%if cnt~=nfbres
-%   error('Check lagged restrictions in foreign equations!')
-%end
-%%
-%for kj=1:nfvar
-%   Ri(1:nfbres,:,kj) = bfor;
-%end
-
-
-%===== Lagged restrictions in home (affected) block
-%
-%~~~~~ selected domestic equations
-%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
-%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
-%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
-%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
-%bhom = zeros(nhbres,k);  % each home equation
-%cnt=0;
-%for ki = 1:lags
-%   for kj=1:length(rfvindx)
-%      cnt=cnt+1;
-%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
-%   end
-%end
-%%
-%if cnt~=nhbres
-%   error('Check lagged restrictions in domestic equations!')
-%end
-%%
-%for kj=dlrindx
-%   Ri(1:nhbres,:,kj) = bhom;
-%end
-
-
-for n=1:nvar   %  initializing loop for each equation
-   Ui{n} = null(Qi(:,:,n));
-   Vi{n} = null(Ri(:,:,n));
-   n0(n) = size(Ui{n},2);
-   np(n) = size(Vi{n},2);
-end
-
-
-
-%(2)-------------------------------------------------------------
-%  Cross-A0-and-A+ rerestrictions one quation at a time
-%    i.e., the first, second, ..., kjth, ..., equation
-%(2)-------------------------------------------------------------
-%
-if indxC0Pres
-   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
-   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
-           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-   %** 1st equation
-   ixmC0Pres{1} = [1 2 2 1
-                   1 7 1 1];
-   %** 2nd equation
-   ixmC0Pres{2} = [2 2 2 2];
-   %** 3rd equation
-   ixmC0Pres{3} = [3 7 1 1
-                   3 2 2 1];
-
-
-%         % 4 columns.
-%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
-
-%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
-%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
-%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
-%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
-else
-   ixmC0Pres = NaN;
-end
-
+function [Ui,Vi,n0,np,ixmC0Pres] = ftd_upperchol7v(lags,nvar,nexo,indxC0Pres)
+%  vlist = [127 124 2 93 141 21];    % 1: Pcom 2 (exchange rate 21); 2: M3 141 (M2 140); 3: R; 4: GDP; 5: GDP deflator 124 (consumption deflator 79).
+%  varlist={'y', 'P', 'Pcom', 'R', 'M3', 'Ex'};
+%
+%    Exporting orthonormal matrices for the deterministic linear restrictions (equation by equation)
+%    See Waggoner and Zha's Gibbs sampling paper.
+%
+% q_m:  quarter or month
+% lags: the maximum length of lag
+% nvar:  number of endogeous variables
+% nexo:  number of exogenous variables.  If nexo is not supplied, nexo=1 as default for a constant
+% indxC0Pres: index for cross-A0-A+ restrictions.  if 1: cross-A0-and-A+ restrictions; 0: idfile is all we have
+%                Example for indxOres==1: restrictions of the form P(t) = P(t-1).
+%                These restrictions have to be manually and carefully keyed in.
+%-----------------
+% Ui: nvar-by-1 cell.  In each cell, nvar-by-qi orthonormal basis for the null of the ith
+%           equation contemporaneous restriction matrix where qi is the number of free parameters.
+%           With this transformation, we have ai = Ui*bi or Ui'*ai = bi where ai is a vector
+%           of total original parameters and bi is a vector of free parameters. When no
+%           restrictions are imposed, we have Ui = I.  There must be at least one free
+%           parameter left for the ith equation.
+% Vi: nvar-by-1 cell.  In each cell, k-by-ri orthonormal basis for the null of the ith
+%           equation lagged restriction matrix where k is a total of exogenous variables and
+%           ri is the number of free parameters. With this transformation, we have fi = Vi*gi
+%           or Vi'*fi = gi where fi is a vector of total original parameters and gi is a
+%           vector of free parameters. There must be at least one free parameter left for
+%           the ith equation.
+% n0: nvar-by-1, ith element represents the number of free A0 parameters in ith equation
+% np: nvar-by-1, ith element represents the number of free A+ parameters in ith equation
+% ixmC0Pres:  neq_cres-by-1 cell.  Effective only if indxC0Pres=1, otherwise equals NaN.
+%             neq_cres is the number of equations in which cross-A0-A+ restrictions occur.
+%             In the jth cell representing equation, we have 4 columns:
+%               1st: the jth column (equation) of A+ or A0: f_j or a_j
+%               2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%               3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%               4th: the number s such that f_j(i) = s * a_j(h) holds.
+%
+% Tao Zha, May 2000
+
+
+
+Ui = cell(nvar,1);  % initializing for contemporaneous endogenous variables
+Vi = cell(nvar,1);  % initializing for lagged and exogenous variables
+n0 = zeros(nvar,1); % ith element represents the number of free A0 parameters in ith equation
+np = zeros(nvar,1); % ith element represents the number of free A+ parameters in ith equation
+
+if (nargin==2)
+   nexo = 1;  % 1: constant as default where nexo must be a nonnegative integer
+elseif (nargin==3)
+   indxC0Pres = 0;  % default is no cross-A0-and-A+ restrictions.
+end
+
+k = lags*nvar+nexo;  % maximum number of lagged and exogenous variables in each equation
+
+Qi = zeros(nvar,nvar,nvar);   % for nvar contemporaneous equations
+Ri = zeros(k,k,nvar);    % for nvar lagged and exogenous equations
+  % Row corresponds to equation. 0 means no restriction.
+  %                              1 means exclusion restriction such that the corresponding parameter is restricted to 0.
+
+%nfvar = 6;   % number of foreign (Granger causing) variables
+%nhvar = nvar-nfvar;  % number of home (affected) variables.
+
+
+%-------------------------------------------------------------
+%  Beginning the manual input of the restrictions one quation at a time
+%-------------------------------------------------------------
+%
+%======== The first equation ===========
+Qi(1:6,:,1) = [
+    0 1 0 0 0 0 0
+    0 0 1 0 0 0 0
+    0 0 0 1 0 0 0
+    0 0 0 0 1 0 0
+    0 0 0 0 0 1 0
+    0 0 0 0 0 0 1
+        ];
+
+%======== The second equation ===========
+Qi(1:5,:,2) = [
+    0 0 1 0 0 0 0
+    0 0 0 1 0 0 0
+    0 0 0 0 1 0 0
+    0 0 0 0 0 1 0
+    0 0 0 0 0 0 1
+        ];
+
+%======== The third equation ===========
+Qi(1:4,:,3) = [
+    0 0 0 1 0 0 0
+    0 0 0 0 1 0 0
+    0 0 0 0 0 1 0
+    0 0 0 0 0 0 1
+        ];
+
+%======== The fourth equation ===========
+Qi(1:3,:,4) = [
+    0 0 0 0 1 0 0
+    0 0 0 0 0 1 0
+    0 0 0 0 0 0 1
+        ];
+
+
+%======== The fifth equation ===========
+Qi(1:2,:,5) = [
+    0 0 0 0 0 1 0
+    0 0 0 0 0 0 1
+         ];
+
+
+%======== The sixth equation ===========
+Qi(1:1,:,6) = [
+    0 0 0 0 0 0 1
+         ];
+
+
+%======== The seventh equation ===========
+
+%===== Lagged restrictions in foreign (Granger causing) block
+%nfbres = lags*(nvar-nfvar);  % number of block restrictions in each foreign equation
+%bfor = zeros(nfbres,k);  % each foreign equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:nvar-nfvar
+%      cnt=cnt+1;
+%      bfor(cnt,nvar*(ki-1)+nfvar+kj) = 1;
+%   end
+%end
+%%
+%if cnt~=nfbres
+%   error('Check lagged restrictions in foreign equations!')
+%end
+%%
+%for kj=1:nfvar
+%   Ri(1:nfbres,:,kj) = bfor;
+%end
+
+
+%===== Lagged restrictions in home (affected) block
+%
+%~~~~~ selected domestic equations
+%dlrindx = nfvar+1; %[nfvar+1 nfvar+2];  % index for relevant home equations
+%rfvindx = []; %[6];  %[1 2 3 5];  % index for restricted foreign variables (e.g., Poil, M2, FFR, P).
+%%nf2hvar = nfvar-length(rfvindx);  % number of free parameters -- foreign variables entering the home sector
+%nhbres = lags*length(rfvindx);  % number of block restrictions in each home equation
+%bhom = zeros(nhbres,k);  % each home equation
+%cnt=0;
+%for ki = 1:lags
+%   for kj=1:length(rfvindx)
+%      cnt=cnt+1;
+%      bhom(cnt,nvar*(ki-1)+rfvindx(kj)) = 1;
+%   end
+%end
+%%
+%if cnt~=nhbres
+%   error('Check lagged restrictions in domestic equations!')
+%end
+%%
+%for kj=dlrindx
+%   Ri(1:nhbres,:,kj) = bhom;
+%end
+
+
+for n=1:nvar   %  initializing loop for each equation
+   Ui{n} = null(Qi(:,:,n));
+   Vi{n} = null(Ri(:,:,n));
+   n0(n) = size(Ui{n},2);
+   np(n) = size(Vi{n},2);
+end
+
+
+
+%(2)-------------------------------------------------------------
+%  Cross-A0-and-A+ rerestrictions one quation at a time
+%    i.e., the first, second, ..., kjth, ..., equation
+%(2)-------------------------------------------------------------
+%
+if indxC0Pres
+   neq_cres = 3;   % the number of equations in which cross-A0-A+ restrictions occur.
+   ixmC0Pres = cell(neq_cres,1);  % in each cell representing equation, we have 4 columns:
+           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+   %** 1st equation
+   ixmC0Pres{1} = [1 2 2 1
+                   1 7 1 1];
+   %** 2nd equation
+   ixmC0Pres{2} = [2 2 2 2];
+   %** 3rd equation
+   ixmC0Pres{3} = [3 7 1 1
+                   3 2 2 1];
+
+
+%         % 4 columns.
+%   ncres = 5;  % manually key in the number of cross-A0-A+ restrictions
+
+%           % 1st: the jth column (equation) of A+ or A0: f_j or a_j
+%           % 2nd: the ith element f_j(i) -- the ith element in the jth column of A+
+%           % 3rd: the hth element a_j(h) -- the hth element in the jth column of A0
+%           % 4th: the number s such that f_j(i) = s * a_j(h) holds.
+else
+   ixmC0Pres = NaN;
+end
+
diff --git a/tests/optimal_policy/nk_ramsey.mod b/tests/optimal_policy/nk_ramsey.mod
index c83cccc5e4..3b35cf51c8 100644
--- a/tests/optimal_policy/nk_ramsey.mod
+++ b/tests/optimal_policy/nk_ramsey.mod
@@ -1,90 +1,90 @@
-//MODEL:
-//test on Dynare to find the lagrangean multipliers.
-//We consider a standard NK model. We use the FOCS of the competitive economy and we aim at calculating the Ramsey optimal problem.
-
-//------------------------------------------------------------------------------------------------------------------------
-//1. Variable declaration
-//------------------------------------------------------------------------------------------------------------------------
-
-var pai, c, n, r, a;
-
-//4 variables + 1 shock
-
-varexo u;
-
-
-
-
-//------------------------------------------------------------------------------------------------------------------------
-// 2. Parameter declaration and calibration
-//-------------------------------------------------------------------------------------------------------------------------
-
-parameters beta, rho, epsilon, omega, phi, gamma;
-
-beta=0.99;
-gamma=3;       //Frish elasticity
-omega=17;        //price stickyness
-epsilon=8;      //elasticity for each variety of consumption
-phi=1;           //coefficient associated to labor effort disutility
-
-rho=0.95;  //coefficient associated to productivity shock
-
-
-//-----------------------------------------------------------------------------------------------------------------------
-// 3. The model
-//-----------------------------------------------------------------------------------------------------------------------
-
-
-model;
-
-
-a=rho*(a(-1))+u;
-
-1/c=beta*(1/(c(+1)))*(r/(pai(+1)));               //euler
-
-
-omega*pai*(pai-1)=beta*omega*(c/(c(+1)))*(pai(+1))*(pai(+1)-1)+epsilon*exp(a)*n*(c/exp(a)*phi*n^gamma-(epsilon-1)/epsilon);  //NK pc
-//pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega-exp(a)*n*(epsilon-1)/(omega*c);  //NK pc
-
-(exp(a))*n=c+(omega/2)*((pai-1)^2);
-
-end;
-
-//--------------------------------------------------------------------------------------------------------------------------
-// 4. Steady state
-//---------------------------------------------------------------------------------------------------------------------------
-
-initval;
-
-pai=1;
-r=1/beta;
-c=0.9671684882;
-n=0.9671684882;
-a=0;
-
-
-end;
-
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-// 5. shocks
-//---------------------------------------------------------------------------------------------------------------------------
-
-shocks;
-var u; stderr 0.008;
-
-end;
-
-//--------------------------------------------------------------------------------------------------------------------------
-// 6. Ramsey problem
-//--------------------------------------------------------------------------------------------------------------------------
-
-planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
-
-write_latex_static_model;
-
-ramsey_policy(planner_discount=0.99);
-
-
-
+//MODEL:
+//test on Dynare to find the lagrangean multipliers.
+//We consider a standard NK model. We use the FOCS of the competitive economy and we aim at calculating the Ramsey optimal problem.
+
+//------------------------------------------------------------------------------------------------------------------------
+//1. Variable declaration
+//------------------------------------------------------------------------------------------------------------------------
+
+var pai, c, n, r, a;
+
+//4 variables + 1 shock
+
+varexo u;
+
+
+
+
+//------------------------------------------------------------------------------------------------------------------------
+// 2. Parameter declaration and calibration
+//-------------------------------------------------------------------------------------------------------------------------
+
+parameters beta, rho, epsilon, omega, phi, gamma;
+
+beta=0.99;
+gamma=3;       //Frish elasticity
+omega=17;        //price stickyness
+epsilon=8;      //elasticity for each variety of consumption
+phi=1;           //coefficient associated to labor effort disutility
+
+rho=0.95;  //coefficient associated to productivity shock
+
+
+//-----------------------------------------------------------------------------------------------------------------------
+// 3. The model
+//-----------------------------------------------------------------------------------------------------------------------
+
+
+model;
+
+
+a=rho*(a(-1))+u;
+
+1/c=beta*(1/(c(+1)))*(r/(pai(+1)));               //euler
+
+
+omega*pai*(pai-1)=beta*omega*(c/(c(+1)))*(pai(+1))*(pai(+1)-1)+epsilon*exp(a)*n*(c/exp(a)*phi*n^gamma-(epsilon-1)/epsilon);  //NK pc
+//pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega-exp(a)*n*(epsilon-1)/(omega*c);  //NK pc
+
+(exp(a))*n=c+(omega/2)*((pai-1)^2);
+
+end;
+
+//--------------------------------------------------------------------------------------------------------------------------
+// 4. Steady state
+//---------------------------------------------------------------------------------------------------------------------------
+
+initval;
+
+pai=1;
+r=1/beta;
+c=0.9671684882;
+n=0.9671684882;
+a=0;
+
+
+end;
+
+
+
+//---------------------------------------------------------------------------------------------------------------------------
+// 5. shocks
+//---------------------------------------------------------------------------------------------------------------------------
+
+shocks;
+var u; stderr 0.008;
+
+end;
+
+//--------------------------------------------------------------------------------------------------------------------------
+// 6. Ramsey problem
+//--------------------------------------------------------------------------------------------------------------------------
+
+planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
+
+write_latex_static_model;
+
+ramsey_policy(planner_discount=0.99);
+
+
+
diff --git a/tests/optimal_policy/nk_ramsey_expectation.mod b/tests/optimal_policy/nk_ramsey_expectation.mod
index 6ef787945e..00212c000c 100644
--- a/tests/optimal_policy/nk_ramsey_expectation.mod
+++ b/tests/optimal_policy/nk_ramsey_expectation.mod
@@ -1,96 +1,96 @@
-//MODEL:
-// test for using expectation operator with Ramsey policy
-// The results is validated by comparing with replacing manually the expectation with an
-// auxiliary variable in nk_ramsey_expectation_a.mod
-// Note that the example doesn't make any sense from an economic point of view.
-
-
-//------------------------------------------------------------------------------------------------------------------------
-//1. Variable declaration
-//------------------------------------------------------------------------------------------------------------------------
-
-var pai, c, n, r, a;
-
-//4 variables + 1 shock
-
-varexo u;
-
-
-
-
-//------------------------------------------------------------------------------------------------------------------------
-// 2. Parameter declaration and calibration
-//-------------------------------------------------------------------------------------------------------------------------
-
-parameters beta, rho, epsilon, omega, phi, gamma;
-
-beta=0.99;
-gamma=3;       //Frish elasticity
-omega=17;        //price stickyness
-epsilon=8;      //elasticity for each variety of consumption
-phi=1;           //coefficient associated to labor effort disutility
-
-rho=0.95;  //coefficient associated to productivity shock
-
-
-//-----------------------------------------------------------------------------------------------------------------------
-// 3. The model
-//-----------------------------------------------------------------------------------------------------------------------
-
-
-model;
-
-
-a=rho*(a(-1))+u;
-
-1/c=beta*(1/(c(+1)))*(r/expectation(0)(pai(+1)));               //euler
-
-
-omega*pai*(pai-1)=beta*omega*(c/(c(+1)))*(pai(+1))*(pai(+1)-1)+epsilon*exp(a)*n*(c/exp(a)*phi*n^gamma-(epsilon-1)/epsilon);  //NK pc
-//pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega-exp(a)*n*(epsilon-1)/(omega*c);  //NK pc
-
-(exp(a))*n=c+(omega/2)*((pai-1)^2);
-
-end;
-
-//--------------------------------------------------------------------------------------------------------------------------
-// 4. Steady state
-//---------------------------------------------------------------------------------------------------------------------------
-
-initval;
-% this is the exact steady state under optimal policy
-%important for the comparison
-
-pai=1;
-r=1/beta;
-c=((epsilon-1)/(epsilon*phi))^(1/(1+gamma));
-n=c;
-a=0;
-
-end;
-
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-// 5. shocks
-//---------------------------------------------------------------------------------------------------------------------------
-
-shocks;
-var u; stderr 0.008;
-
-end;
-
-//--------------------------------------------------------------------------------------------------------------------------
-// 6. Ramsey problem
-//--------------------------------------------------------------------------------------------------------------------------
-
-planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
-
-write_latex_static_model;
-write_latex_dynamic_model;
-
-options_.solve_tolf=1e-12;
-ramsey_policy(planner_discount=0.99);
-
-
-
+//MODEL:
+// test for using expectation operator with Ramsey policy
+// The results is validated by comparing with replacing manually the expectation with an
+// auxiliary variable in nk_ramsey_expectation_a.mod
+// Note that the example doesn't make any sense from an economic point of view.
+
+
+//------------------------------------------------------------------------------------------------------------------------
+//1. Variable declaration
+//------------------------------------------------------------------------------------------------------------------------
+
+var pai, c, n, r, a;
+
+//4 variables + 1 shock
+
+varexo u;
+
+
+
+
+//------------------------------------------------------------------------------------------------------------------------
+// 2. Parameter declaration and calibration
+//-------------------------------------------------------------------------------------------------------------------------
+
+parameters beta, rho, epsilon, omega, phi, gamma;
+
+beta=0.99;
+gamma=3;       //Frish elasticity
+omega=17;        //price stickyness
+epsilon=8;      //elasticity for each variety of consumption
+phi=1;           //coefficient associated to labor effort disutility
+
+rho=0.95;  //coefficient associated to productivity shock
+
+
+//-----------------------------------------------------------------------------------------------------------------------
+// 3. The model
+//-----------------------------------------------------------------------------------------------------------------------
+
+
+model;
+
+
+a=rho*(a(-1))+u;
+
+1/c=beta*(1/(c(+1)))*(r/expectation(0)(pai(+1)));               //euler
+
+
+omega*pai*(pai-1)=beta*omega*(c/(c(+1)))*(pai(+1))*(pai(+1)-1)+epsilon*exp(a)*n*(c/exp(a)*phi*n^gamma-(epsilon-1)/epsilon);  //NK pc
+//pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega-exp(a)*n*(epsilon-1)/(omega*c);  //NK pc
+
+(exp(a))*n=c+(omega/2)*((pai-1)^2);
+
+end;
+
+//--------------------------------------------------------------------------------------------------------------------------
+// 4. Steady state
+//---------------------------------------------------------------------------------------------------------------------------
+
+initval;
+% this is the exact steady state under optimal policy
+%important for the comparison
+
+pai=1;
+r=1/beta;
+c=((epsilon-1)/(epsilon*phi))^(1/(1+gamma));
+n=c;
+a=0;
+
+end;
+
+
+
+//---------------------------------------------------------------------------------------------------------------------------
+// 5. shocks
+//---------------------------------------------------------------------------------------------------------------------------
+
+shocks;
+var u; stderr 0.008;
+
+end;
+
+//--------------------------------------------------------------------------------------------------------------------------
+// 6. Ramsey problem
+//--------------------------------------------------------------------------------------------------------------------------
+
+planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
+
+write_latex_static_model;
+write_latex_dynamic_model;
+
+options_.solve_tolf=1e-12;
+ramsey_policy(planner_discount=0.99);
+
+
+
diff --git a/tests/optimal_policy/nk_ramsey_expectation_a.mod b/tests/optimal_policy/nk_ramsey_expectation_a.mod
index cbd7a5f341..8755e7f367 100644
--- a/tests/optimal_policy/nk_ramsey_expectation_a.mod
+++ b/tests/optimal_policy/nk_ramsey_expectation_a.mod
@@ -1,104 +1,104 @@
-//MODEL:
-// test for using expectation operator with Ramsey policy
-// Here, the expected variable is replaced manually with an auxiliary variable (epai)
-// We check that the result is the same as with an explicit expectation operator in nk_ramsey_expectation.mod
-// Note that the example doesn't make any sense from an economic point of view.
-
-//------------------------------------------------------------------------------------------------------------------------
-//1. Variable declaration
-//------------------------------------------------------------------------------------------------------------------------
-
-var pai, c, n, r, a, epai;
-
-//4 variables + 1 shock
-
-varexo u;
-
-
-
-
-//------------------------------------------------------------------------------------------------------------------------
-// 2. Parameter declaration and calibration
-//-------------------------------------------------------------------------------------------------------------------------
-
-parameters beta, rho, epsilon, omega, phi, gamma;
-
-beta=0.99;
-gamma=3;       //Frish elasticity
-omega=17;        //price stickyness
-epsilon=8;      //elasticity for each variety of consumption
-phi=1;           //coefficient associated to labor effort disutility
-
-rho=0.95;  //coefficient associated to productivity shock
-
-
-//-----------------------------------------------------------------------------------------------------------------------
-// 3. The model
-//-----------------------------------------------------------------------------------------------------------------------
-
-
-model;
-
-
-a=rho*(a(-1))+u;
-
-1/c=beta*(1/(c(+1)))*(r/epai);               //euler
-
-
-omega*pai*(pai-1)=beta*omega*(c/(c(+1)))*(pai(+1))*(pai(+1)-1)+epsilon*exp(a)*n*(c/exp(a)*phi*n^gamma-(epsilon-1)/epsilon);  //NK pc
-//pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega-exp(a)*n*(epsilon-1)/(omega*c);  //NK pc
-
-(exp(a))*n=c+(omega/2)*((pai-1)^2);
-
-epai = pai(+1);
-end;
-
-//--------------------------------------------------------------------------------------------------------------------------
-// 4. Steady state
-//---------------------------------------------------------------------------------------------------------------------------
-
-initval;
-% this is the exact steady state under optimal policy
-%important for the comparison
-
-pai=1;
-epai=1;
-r=1/beta;
-c=((epsilon-1)/(epsilon*phi))^(1/(1+gamma));
-n=c;
-a=0;
-
-
-end;
-
-
-
-//---------------------------------------------------------------------------------------------------------------------------
-// 5. shocks
-//---------------------------------------------------------------------------------------------------------------------------
-
-shocks;
-var u; stderr 0.008;
-
-end;
-
-//--------------------------------------------------------------------------------------------------------------------------
-// 6. Ramsey problem
-//--------------------------------------------------------------------------------------------------------------------------
-
-planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
-
-options_.solve_tolf=1e-12;
-ramsey_policy(planner_discount=0.99);
-
-o1=load('nk_ramsey_expectation_results');
-if (norm(o1.oo_.dr.ghx-oo_.dr.ghx,inf) > 1e-12)
-   error('ghx doesn''t match')
-end
-if (norm(o1.oo_.dr.ghu-oo_.dr.ghu,inf) > 1e-12)
-   error('ghu doesn''t match')
-end
-if (abs(o1.oo_.planner_objective_value(1)-oo_.planner_objective_value(1)) > 1e-12)
-   error('planner objective value doesn''t match')
-end
-
+//MODEL:
+// test for using expectation operator with Ramsey policy
+// Here, the expected variable is replaced manually with an auxiliary variable (epai)
+// We check that the result is the same as with an explicit expectation operator in nk_ramsey_expectation.mod
+// Note that the example doesn't make any sense from an economic point of view.
+
+//------------------------------------------------------------------------------------------------------------------------
+//1. Variable declaration
+//------------------------------------------------------------------------------------------------------------------------
+
+var pai, c, n, r, a, epai;
+
+//4 variables + 1 shock
+
+varexo u;
+
+
+
+
+//------------------------------------------------------------------------------------------------------------------------
+// 2. Parameter declaration and calibration
+//-------------------------------------------------------------------------------------------------------------------------
+
+parameters beta, rho, epsilon, omega, phi, gamma;
+
+beta=0.99;
+gamma=3;       //Frish elasticity
+omega=17;        //price stickyness
+epsilon=8;      //elasticity for each variety of consumption
+phi=1;           //coefficient associated to labor effort disutility
+
+rho=0.95;  //coefficient associated to productivity shock
+
+
+//-----------------------------------------------------------------------------------------------------------------------
+// 3. The model
+//-----------------------------------------------------------------------------------------------------------------------
+
+
+model;
+
+
+a=rho*(a(-1))+u;
+
+1/c=beta*(1/(c(+1)))*(r/epai);               //euler
+
+
+omega*pai*(pai-1)=beta*omega*(c/(c(+1)))*(pai(+1))*(pai(+1)-1)+epsilon*exp(a)*n*(c/exp(a)*phi*n^gamma-(epsilon-1)/epsilon);  //NK pc
+//pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega-exp(a)*n*(epsilon-1)/(omega*c);  //NK pc
+
+(exp(a))*n=c+(omega/2)*((pai-1)^2);
+
+epai = pai(+1);
+end;
+
+//--------------------------------------------------------------------------------------------------------------------------
+// 4. Steady state
+//---------------------------------------------------------------------------------------------------------------------------
+
+initval;
+% this is the exact steady state under optimal policy
+%important for the comparison
+
+pai=1;
+epai=1;
+r=1/beta;
+c=((epsilon-1)/(epsilon*phi))^(1/(1+gamma));
+n=c;
+a=0;
+
+
+end;
+
+
+
+//---------------------------------------------------------------------------------------------------------------------------
+// 5. shocks
+//---------------------------------------------------------------------------------------------------------------------------
+
+shocks;
+var u; stderr 0.008;
+
+end;
+
+//--------------------------------------------------------------------------------------------------------------------------
+// 6. Ramsey problem
+//--------------------------------------------------------------------------------------------------------------------------
+
+planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
+
+options_.solve_tolf=1e-12;
+ramsey_policy(planner_discount=0.99);
+
+o1=load('nk_ramsey_expectation_results');
+if (norm(o1.oo_.dr.ghx-oo_.dr.ghx,inf) > 1e-12)
+   error('ghx doesn''t match')
+end
+if (norm(o1.oo_.dr.ghu-oo_.dr.ghu,inf) > 1e-12)
+   error('ghu doesn''t match')
+end
+if (abs(o1.oo_.planner_objective_value(1)-oo_.planner_objective_value(1)) > 1e-12)
+   error('planner objective value doesn''t match')
+end
+
diff --git a/tests/pi2004/idata.m b/tests/pi2004/idata.m
index 9ce34b9eb7..e7a5a2c509 100644
--- a/tests/pi2004/idata.m
+++ b/tests/pi2004/idata.m
@@ -1,5 +1,5 @@
-load ych.dat;
-data = log(ych);
-oy = data(:,1);
-oc = data(:,2);
+load ych.dat;
+data = log(ych);
+oy = data(:,1);
+oc = data(:,2);
 oh = data(:,3);
\ No newline at end of file
diff --git a/tests/practicing/datasaver.m b/tests/practicing/datasaver.m
index 2c72e20e16..0ac532a4ae 100644
--- a/tests/practicing/datasaver.m
+++ b/tests/practicing/datasaver.m
@@ -1,58 +1,58 @@
-function datasaver (s,var_list)
-% datasaver saves variables simulated by Dynare
-% INPUT
-%    s: a string containing the name of the destination *.m file
-%    var_list: a character matrix containting the name of the variables
-%              to be saved (optional, default: all endogenous variables)
-% OUTPUT
-%    none
-% This is part of the examples included in F. Barillas, R. Colacito,
-% S. Kitao, C. Matthes, T. Sargent and Y. Shin (2007) "Practicing
-% Dynare".
-  
-% Modified by M. Juillard to make it also compatible with Dynare 
-% version 4 (12/4/07)   
-  
-
-global lgy_ lgx_ y_ endo_nbr M_ oo_
-
-% test and adapt for Dynare version 4
-if isempty(lgy_)
-  lgy_ = M_.endo_names;
-  lgx_ + M_.exo_names;
-  y_ = oo_.endo_simul;
-  endo_nbr = M_.endo_nbr;
-end
-
-sm=[s,'.m'];
-fid=fopen(sm,'w') ;
-
-n = size(var_list,1);
-if n == 0
-  n = endo_nbr;
-  ivar = [1:n]';
-  var_list = lgy_;
-else
-  ivar=zeros(n,1);
-  for i=1:n
-    i_tmp = strmatch(var_list(i,:),lgy_,'exact');
-    if isempty(i_tmp)
-      error (['One of the specified variables does not exist']) ;
-    else
-      ivar(i) = i_tmp;
-    end
-  end
-end
-
-
-for i = 1:n
-	fprintf(fid,[lgy_(ivar(i),:), '=['],'\n') ;
-	fprintf(fid,'\n') ;
-	fprintf(fid,'%15.8g\n',y_(ivar(i),:)') ;
-   	fprintf(fid,'\n') ;
-   	fprintf(fid,'];\n') ;
-  	fprintf(fid,'\n') ;
-end
-fclose(fid) ;
-
-return ;
+function datasaver (s,var_list)
+% datasaver saves variables simulated by Dynare
+% INPUT
+%    s: a string containing the name of the destination *.m file
+%    var_list: a character matrix containting the name of the variables
+%              to be saved (optional, default: all endogenous variables)
+% OUTPUT
+%    none
+% This is part of the examples included in F. Barillas, R. Colacito,
+% S. Kitao, C. Matthes, T. Sargent and Y. Shin (2007) "Practicing
+% Dynare".
+  
+% Modified by M. Juillard to make it also compatible with Dynare 
+% version 4 (12/4/07)   
+  
+
+global lgy_ lgx_ y_ endo_nbr M_ oo_
+
+% test and adapt for Dynare version 4
+if isempty(lgy_)
+  lgy_ = M_.endo_names;
+  lgx_ + M_.exo_names;
+  y_ = oo_.endo_simul;
+  endo_nbr = M_.endo_nbr;
+end
+
+sm=[s,'.m'];
+fid=fopen(sm,'w') ;
+
+n = size(var_list,1);
+if n == 0
+  n = endo_nbr;
+  ivar = [1:n]';
+  var_list = lgy_;
+else
+  ivar=zeros(n,1);
+  for i=1:n
+    i_tmp = strmatch(var_list(i,:),lgy_,'exact');
+    if isempty(i_tmp)
+      error (['One of the specified variables does not exist']) ;
+    else
+      ivar(i) = i_tmp;
+    end
+  end
+end
+
+
+for i = 1:n
+	fprintf(fid,[lgy_(ivar(i),:), '=['],'\n') ;
+	fprintf(fid,'\n') ;
+	fprintf(fid,'%15.8g\n',y_(ivar(i),:)') ;
+   	fprintf(fid,'\n') ;
+   	fprintf(fid,'];\n') ;
+  	fprintf(fid,'\n') ;
+end
+fclose(fid) ;
+
+return ;
diff --git a/tests/recursive/data_ca1.m b/tests/recursive/data_ca1.m
index b0b4f05461..c28fae1a28 100644
--- a/tests/recursive/data_ca1.m
+++ b/tests/recursive/data_ca1.m
@@ -1,100 +1,100 @@
-data = [0.928467646476  11.8716889412   20  0.418037507392  0.227382377518 ...
--0.705994063083 11.7522582094   21.25   1.09254424511   -1.29488274994 ...
--0.511895351926 9.68144025625   17.25   -1.66150408407  0.331508393098 ...
--0.990955971267 10.0890781236   17  1.43016275252   -2.43589670141 ...
--0.981233061806 12.1094840679   18.25   2.91293288733   -0.790246576864 ...
--0.882182844512 8.54559460406   15  0.419579139481  0.358729719566 ...
--0.930893002836 6.19238374422   12.5    -1.48847457959  0.739779938797 ...
-1.53158206947   2.76544271886   11.5    -0.336216769682 0.455559918769 ...
-2.2659052834    5.47418162513   11  0.306436789767  -0.0707985731221 ...
-1.05419803797   6.35698426189   11  0.140700250477  0.620401487202 ...
-1.20161076793   3.4253301593    11  0.461296492351  0.14354323987 ...
-1.73934077971   4.70926070322   11.5    1.35798282982   0.38564694435 ...
-1.71735262584   3.54232079749   12.5    2.9097529155    -0.804308583301 ...
-0.426343657844  3.32719108897   13  1.64214862652   -1.18214664701 ...
-1.67751812324   2.93444727338   11.25   0.344434910651  -1.6529373719 ...
-1.37013301099   4.72303361923   11.75   2.61511526582   0.327684243041 ...
-0.281231073781  4.4893853071    10.5    1.17043449257   1.12855106649 ...
-1.53638992834   3.7325309699    10.25   -0.683947046728 0.11943538737 ...
-1.68081431462   3.34729969129   10  1.41159342106   -1.59065680853 ...
--0.343321601133 5.05563513564   12  1.75117366498   -2.40127764642 ...
-0.873415608666  3.2779996255    10.25   -1.39895866711  0.0971444398216 ...
-0.26399696544   4.78229419828   9.75    0.0914692438124 0.299310457612 ...
--0.562233624818 3.88598638237   9.75    -0.0505384765105    0.332826708151 ...
-2.15161914936   3.84859710132   8.75    -3.44811080489  0.789138678784 ...
-1.2345093726    5.62225030942   9.5 -0.366945407434 2.32974981198 ...
-1.62554967459   4.24667132831   10  -0.800958371402 0.0293183770935 ...
-1.33035402527   2.75248979249   9.75    -0.855723113225 0.852493939813 ...
-1.52078814077   3.53415985826   9.75    -3.37963469203  -1.05133958119 ...
-1.16704983697   4.92754079464   10.75   -3.0142303324   0.459907431978 ...
-0.277213572101  4.55532133037   11.75   -0.851995599415 2.03242034852 ...
-0.842215068977  3.11164509647   12.25   -1.08290421696  0.014323281961 ...
-1.05325028606   4.92882647578   13.5    -1.1953883867   0.706764750654 ...
-0.453051253568  6.82998950103   13.5    0.111803656462  0.088462593153 ...
-0.199885995525  5.82643354662   13.5    -0.920501518421 -0.26504958666 ...
-0.137907999624  2.66076369132   13.5    -1.17122929812  -0.995642430514 ...
-0.721949686709  5.70497876823   14.25   1.19378169018   -1.10644839651 ...
--0.418465249225 3.75861110232   14.75   -1.03131674824  0.188507675831 ...
--0.644028342116 4.15104788154   13.75   -1.48911756546  0.204560913792 ...
--0.848213852668 5.65580324027   12.75   0.677011703877  -0.849628054542 ...
--1.51954076928  11.4866911266   11.25   -0.446024680774 -0.456342350765 ...
-0.265275055215  2.85472749592   9.75    -0.598778202436 -0.907311640831 ...
-0.356162529063  2.29614015658   9.5 -0.46820788432  -1.22130883441 ...
-0.368308864363  -0.539083504685 8   -0.781333991956 0.374007246518 ...
--0.145751412732 1.61507621789   8.25    3.68291932628   1.32438399845 ...
-0.285457283664  2.14334055993   7   1.42819405379   -0.00818660844123 ...
-0.372390129412  1.60000213334   6.25    0.626106424052  -0.10136772765 ...
-0.382720203063  1.72614243263   7.25    4.89631941021   -1.10060711916 ...
-0.737957515573  2.90430582851   6   -0.0422721010314    0.4178952497 ...
-0.649532581668  0.657135682543  6   0.692066153971  0.422299120276 ...
-0.627159201987  1.70352689913   5.75    2.62066711305   -1.29237304034 ...
-0.905441299817  1.95663197267   5.5 1.5949697565    -0.27115830703 ...
-1.49322577898   -2.08741765309  6.25    1.23027694802   0.418336889527 ...
-1.48750731567   -1.57274121871  8   3.01660550994   -0.893958254365 ...
-1.39783858087   2.22623066426   7   -0.80842319214  1.47625453886 ...
-0.89274836317   1.30378081742   8   -0.249485058661 0.159871204185 ...
-0.920652246088  4.1437741965    9.75    2.8204453623    0.178149239655 ...
--0.00264276644799   3.07989972052   8.75    -2.56342461535  2.105998353 ...
-0.0198190461681 0.766283759256  8   -1.15838865989  1.56888883418 ...
-0.440050515311  0.127570085801  7.5 0.0400753569995 0.028914333532 ...
-0.129536637901  1.78174141526   6.75    0.959943962785  0.307781224401 ...
-0.398549827172  3.03606770667   6.5 -0.340209794742 0.100979469478 ...
-1.17174775425   0.629625188037  5.75    0.403003686814  0.902394579377 ...
-0.991163981251  2.50862910684   4.75    -1.44963996982  1.16150986945 ...
-0.967603566096  2.12003739013   4.75    0.610846030775  -0.889994896068 ...
-1.14689383604   1.24185011459   4.75    2.01098091308   -1.73846431001 ...
-1.32593824054   0.990713820685  4.75    -0.0955142989332    -0.0369257308362 ...
-0.861135002644  -0.24744943605  6   1.72793107135   -0.691506789639 ...
-1.26870850151   2.09844764887   6.5 1.50720217572   -1.31399187077 ...
-0.260364987715  1.10650139716   6.5 1.13659047496   0.0720441664643 ...
-1.09731242214   0.490796381346  7.25    4.59123894147   -2.14073070763 ...
-1.63792841781   0.612652594286  6.75    1.79604605035   -0.644363995357 ...
-1.48465576034   0.978295808687  6.75    -2.00753620902  1.39437534964 ...
-1.0987608663    4.25212569087   6.25    -2.58901196498  2.56054320803 ...
-1.42592178132   2.76984518311   6.25    0.888195752358  1.03114549274 ...
-1.52958239462   1.31795955491   6.5 -0.902907564082 -0.0952198893776 ...
-1.0170168994    2.14733589918   7   -1.3054866978   2.68803738466 ...
-0.723253652257  3.43552889347   7.5 1.8213700853    0.592593586195 ...
-1.24720806008   3.87383806577   7.5 0.0522300654168 0.988871238698 ...
-0.482531471239  2.67793287032   7.5 2.9693944293    -0.108591166081 ...
-0.154056100439  0.927269031704  6.75    0.119222057561  3.30489209451 ...
-0.0694865769274 6.65916526788   6.25    0.889014476084  -2.83976849035 ...
--0.121267434867 0.341442615696  5.25    0.323053239216  -3.49289229012 ...
-0.726473690375  -3.5423730964   4   2.19149290449   -3.20855054004 ...
-1.39271709108   2.63121085718   3.75    0.88406577736   0.75622580197 ...
-1.07502077727   5.88578836799   4.25    -2.55088273352  2.89018116374 ...
-0.759049251607  4.24703604223   4.5 0.575687665685  -0.388292506167 ...
-]; 
- 
-data = reshape(data,5,86)'; 
-y_obs = data(:,1); 
-pie_obs = data(:,2); 
-R_obs = data(:,3); 
-de = data(:,4); 
-dq = data(:,5); 
- 
-%Country: Canada 
-%Sample Range: 1981:2 to 2002:3 
-%Observations: 86 
-%Variables: Real GDP Growth [%], Inflation [annualized %], Nom Rate [%], 
-%           Exchange Rate Change [%], Terms of Trade Change [%] 
+data = [0.928467646476  11.8716889412   20  0.418037507392  0.227382377518 ...
+-0.705994063083 11.7522582094   21.25   1.09254424511   -1.29488274994 ...
+-0.511895351926 9.68144025625   17.25   -1.66150408407  0.331508393098 ...
+-0.990955971267 10.0890781236   17  1.43016275252   -2.43589670141 ...
+-0.981233061806 12.1094840679   18.25   2.91293288733   -0.790246576864 ...
+-0.882182844512 8.54559460406   15  0.419579139481  0.358729719566 ...
+-0.930893002836 6.19238374422   12.5    -1.48847457959  0.739779938797 ...
+1.53158206947   2.76544271886   11.5    -0.336216769682 0.455559918769 ...
+2.2659052834    5.47418162513   11  0.306436789767  -0.0707985731221 ...
+1.05419803797   6.35698426189   11  0.140700250477  0.620401487202 ...
+1.20161076793   3.4253301593    11  0.461296492351  0.14354323987 ...
+1.73934077971   4.70926070322   11.5    1.35798282982   0.38564694435 ...
+1.71735262584   3.54232079749   12.5    2.9097529155    -0.804308583301 ...
+0.426343657844  3.32719108897   13  1.64214862652   -1.18214664701 ...
+1.67751812324   2.93444727338   11.25   0.344434910651  -1.6529373719 ...
+1.37013301099   4.72303361923   11.75   2.61511526582   0.327684243041 ...
+0.281231073781  4.4893853071    10.5    1.17043449257   1.12855106649 ...
+1.53638992834   3.7325309699    10.25   -0.683947046728 0.11943538737 ...
+1.68081431462   3.34729969129   10  1.41159342106   -1.59065680853 ...
+-0.343321601133 5.05563513564   12  1.75117366498   -2.40127764642 ...
+0.873415608666  3.2779996255    10.25   -1.39895866711  0.0971444398216 ...
+0.26399696544   4.78229419828   9.75    0.0914692438124 0.299310457612 ...
+-0.562233624818 3.88598638237   9.75    -0.0505384765105    0.332826708151 ...
+2.15161914936   3.84859710132   8.75    -3.44811080489  0.789138678784 ...
+1.2345093726    5.62225030942   9.5 -0.366945407434 2.32974981198 ...
+1.62554967459   4.24667132831   10  -0.800958371402 0.0293183770935 ...
+1.33035402527   2.75248979249   9.75    -0.855723113225 0.852493939813 ...
+1.52078814077   3.53415985826   9.75    -3.37963469203  -1.05133958119 ...
+1.16704983697   4.92754079464   10.75   -3.0142303324   0.459907431978 ...
+0.277213572101  4.55532133037   11.75   -0.851995599415 2.03242034852 ...
+0.842215068977  3.11164509647   12.25   -1.08290421696  0.014323281961 ...
+1.05325028606   4.92882647578   13.5    -1.1953883867   0.706764750654 ...
+0.453051253568  6.82998950103   13.5    0.111803656462  0.088462593153 ...
+0.199885995525  5.82643354662   13.5    -0.920501518421 -0.26504958666 ...
+0.137907999624  2.66076369132   13.5    -1.17122929812  -0.995642430514 ...
+0.721949686709  5.70497876823   14.25   1.19378169018   -1.10644839651 ...
+-0.418465249225 3.75861110232   14.75   -1.03131674824  0.188507675831 ...
+-0.644028342116 4.15104788154   13.75   -1.48911756546  0.204560913792 ...
+-0.848213852668 5.65580324027   12.75   0.677011703877  -0.849628054542 ...
+-1.51954076928  11.4866911266   11.25   -0.446024680774 -0.456342350765 ...
+0.265275055215  2.85472749592   9.75    -0.598778202436 -0.907311640831 ...
+0.356162529063  2.29614015658   9.5 -0.46820788432  -1.22130883441 ...
+0.368308864363  -0.539083504685 8   -0.781333991956 0.374007246518 ...
+-0.145751412732 1.61507621789   8.25    3.68291932628   1.32438399845 ...
+0.285457283664  2.14334055993   7   1.42819405379   -0.00818660844123 ...
+0.372390129412  1.60000213334   6.25    0.626106424052  -0.10136772765 ...
+0.382720203063  1.72614243263   7.25    4.89631941021   -1.10060711916 ...
+0.737957515573  2.90430582851   6   -0.0422721010314    0.4178952497 ...
+0.649532581668  0.657135682543  6   0.692066153971  0.422299120276 ...
+0.627159201987  1.70352689913   5.75    2.62066711305   -1.29237304034 ...
+0.905441299817  1.95663197267   5.5 1.5949697565    -0.27115830703 ...
+1.49322577898   -2.08741765309  6.25    1.23027694802   0.418336889527 ...
+1.48750731567   -1.57274121871  8   3.01660550994   -0.893958254365 ...
+1.39783858087   2.22623066426   7   -0.80842319214  1.47625453886 ...
+0.89274836317   1.30378081742   8   -0.249485058661 0.159871204185 ...
+0.920652246088  4.1437741965    9.75    2.8204453623    0.178149239655 ...
+-0.00264276644799   3.07989972052   8.75    -2.56342461535  2.105998353 ...
+0.0198190461681 0.766283759256  8   -1.15838865989  1.56888883418 ...
+0.440050515311  0.127570085801  7.5 0.0400753569995 0.028914333532 ...
+0.129536637901  1.78174141526   6.75    0.959943962785  0.307781224401 ...
+0.398549827172  3.03606770667   6.5 -0.340209794742 0.100979469478 ...
+1.17174775425   0.629625188037  5.75    0.403003686814  0.902394579377 ...
+0.991163981251  2.50862910684   4.75    -1.44963996982  1.16150986945 ...
+0.967603566096  2.12003739013   4.75    0.610846030775  -0.889994896068 ...
+1.14689383604   1.24185011459   4.75    2.01098091308   -1.73846431001 ...
+1.32593824054   0.990713820685  4.75    -0.0955142989332    -0.0369257308362 ...
+0.861135002644  -0.24744943605  6   1.72793107135   -0.691506789639 ...
+1.26870850151   2.09844764887   6.5 1.50720217572   -1.31399187077 ...
+0.260364987715  1.10650139716   6.5 1.13659047496   0.0720441664643 ...
+1.09731242214   0.490796381346  7.25    4.59123894147   -2.14073070763 ...
+1.63792841781   0.612652594286  6.75    1.79604605035   -0.644363995357 ...
+1.48465576034   0.978295808687  6.75    -2.00753620902  1.39437534964 ...
+1.0987608663    4.25212569087   6.25    -2.58901196498  2.56054320803 ...
+1.42592178132   2.76984518311   6.25    0.888195752358  1.03114549274 ...
+1.52958239462   1.31795955491   6.5 -0.902907564082 -0.0952198893776 ...
+1.0170168994    2.14733589918   7   -1.3054866978   2.68803738466 ...
+0.723253652257  3.43552889347   7.5 1.8213700853    0.592593586195 ...
+1.24720806008   3.87383806577   7.5 0.0522300654168 0.988871238698 ...
+0.482531471239  2.67793287032   7.5 2.9693944293    -0.108591166081 ...
+0.154056100439  0.927269031704  6.75    0.119222057561  3.30489209451 ...
+0.0694865769274 6.65916526788   6.25    0.889014476084  -2.83976849035 ...
+-0.121267434867 0.341442615696  5.25    0.323053239216  -3.49289229012 ...
+0.726473690375  -3.5423730964   4   2.19149290449   -3.20855054004 ...
+1.39271709108   2.63121085718   3.75    0.88406577736   0.75622580197 ...
+1.07502077727   5.88578836799   4.25    -2.55088273352  2.89018116374 ...
+0.759049251607  4.24703604223   4.5 0.575687665685  -0.388292506167 ...
+]; 
+ 
+data = reshape(data,5,86)'; 
+y_obs = data(:,1); 
+pie_obs = data(:,2); 
+R_obs = data(:,3); 
+de = data(:,4); 
+dq = data(:,5); 
+ 
+%Country: Canada 
+%Sample Range: 1981:2 to 2002:3 
+%Observations: 86 
+%Variables: Real GDP Growth [%], Inflation [annualized %], Nom Rate [%], 
+%           Exchange Rate Change [%], Terms of Trade Change [%] 
diff --git a/tests/steady_state/multi_leads.mod b/tests/steady_state/multi_leads.mod
index 8d6d3c8774..85573c3f8a 100644
--- a/tests/steady_state/multi_leads.mod
+++ b/tests/steady_state/multi_leads.mod
@@ -1,27 +1,27 @@
-    @#define N = 4
-    var A B;
-    varexo eB;
-    parameters Bss rho;
-
-    Bss=1;
-    rho=0.9;
-
-    model;
-    A = B(@{N});
-    B = (1-rho)*Bss +rho*B(-1) +eB;
-    end;
-
-    steady_state_model;
-    A = Bss;
-    B = Bss;
-    end;
-
-    resid;
-    steady;
-    check;
-
-    shocks;
-    var eB ; stderr 1 ;
-    end;
-
-    stoch_simul(order=1,irf=0) ;
+    @#define N = 4
+    var A B;
+    varexo eB;
+    parameters Bss rho;
+
+    Bss=1;
+    rho=0.9;
+
+    model;
+    A = B(@{N});
+    B = (1-rho)*Bss +rho*B(-1) +eB;
+    end;
+
+    steady_state_model;
+    A = Bss;
+    B = Bss;
+    end;
+
+    resid;
+    steady;
+    check;
+
+    shocks;
+    var eB ; stderr 1 ;
+    end;
+
+    stoch_simul(order=1,irf=0) ;
diff --git a/tests/steady_state/walsh1_initval.mod b/tests/steady_state/walsh1_initval.mod
index b99016724f..bcbebc43fa 100644
--- a/tests/steady_state/walsh1_initval.mod
+++ b/tests/steady_state/walsh1_initval.mod
@@ -1,68 +1,68 @@
-var y c k m n R pi z u;
-varexo	e sigma;	 
-// sigma stands for phi in the eq 2.37 p.69
-
-parameters alpha beta delta gamm phi1 eta a b rho  phi2 Psi thetass;  
-//phi1 stands for capital phi in eq.2.68 and 2.69
-//phi2 stands for lowercase phi in eq. 2.66
-
-change_type(var) Psi;
-change_type(parameters) n;
-
-alpha = 0.36;
-beta = 0.989; 
-gamm = 0.5;
-delta = 0.019;
-phi1 = 2;
-phi2 = 0;
-eta = 1;
-a = 0.95;
-b = 2.56;
-rho = 0.95;
-//Psi = 1.47630583;
-thetass = 1.0125;
-
-model;
-
-(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = (a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m)^(-b)+beta*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b)/(1+pi(+1));
-
-Psi*(1-exp(n))^(-eta)/(a*exp(c)^(-b)*(a*exp(c)^(1-b) + (1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y)/exp(n);
-
-(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = beta*exp(R(+1))*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b);
-
-exp(R) = alpha*exp(y)/exp(k(-1)) + 1-delta;
-
-exp(k) = (1-delta)*exp(k(-1))+exp(y)-exp(c);
-
-exp(y) = exp(z)*exp(k(-1))^alpha*exp(n)^(1-alpha);
-
-exp(m) = exp(m(-1))*(u+thetass)/(1+pi);
-
-z = rho*z(-1) + e;
-
-u = gamm*u(-1) + phi2*z(-1) + sigma;
-
-end;
-
-shocks;
-var e; stderr 0.007;
-var sigma;stderr 0.0089;
-end;
-
-n=log(1/3);
-
-initval;
-y =  0.2;
-c =  0.03;
-k =  2.7;
-m =  0.3;
-Psi = 1.5;
-R =  0.01;
-pi = 0.01;
-z = 0;
-u = 0;
-end;
-
-
-steady;
-
+var y c k m n R pi z u;
+varexo	e sigma;	 
+// sigma stands for phi in the eq 2.37 p.69
+
+parameters alpha beta delta gamm phi1 eta a b rho  phi2 Psi thetass;  
+//phi1 stands for capital phi in eq.2.68 and 2.69
+//phi2 stands for lowercase phi in eq. 2.66
+
+change_type(var) Psi;
+change_type(parameters) n;
+
+alpha = 0.36;
+beta = 0.989; 
+gamm = 0.5;
+delta = 0.019;
+phi1 = 2;
+phi2 = 0;
+eta = 1;
+a = 0.95;
+b = 2.56;
+rho = 0.95;
+//Psi = 1.47630583;
+thetass = 1.0125;
+
+model;
+
+(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = (a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m)^(-b)+beta*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b)/(1+pi(+1));
+
+Psi*(1-exp(n))^(-eta)/(a*exp(c)^(-b)*(a*exp(c)^(1-b) + (1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y)/exp(n);
+
+(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = beta*exp(R(+1))*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b);
+
+exp(R) = alpha*exp(y)/exp(k(-1)) + 1-delta;
+
+exp(k) = (1-delta)*exp(k(-1))+exp(y)-exp(c);
+
+exp(y) = exp(z)*exp(k(-1))^alpha*exp(n)^(1-alpha);
+
+exp(m) = exp(m(-1))*(u+thetass)/(1+pi);
+
+z = rho*z(-1) + e;
+
+u = gamm*u(-1) + phi2*z(-1) + sigma;
+
+end;
+
+shocks;
+var e; stderr 0.007;
+var sigma;stderr 0.0089;
+end;
+
+n=log(1/3);
+
+initval;
+y =  0.2;
+c =  0.03;
+k =  2.7;
+m =  0.3;
+Psi = 1.5;
+R =  0.01;
+pi = 0.01;
+z = 0;
+u = 0;
+end;
+
+
+steady;
+
diff --git a/tests/steady_state/walsh1_old_ss.mod b/tests/steady_state/walsh1_old_ss.mod
index 39eb8910d8..1b27d832d0 100644
--- a/tests/steady_state/walsh1_old_ss.mod
+++ b/tests/steady_state/walsh1_old_ss.mod
@@ -1,51 +1,51 @@
-var y c k m n R pi z u;
-varexo	e sigma;	 
-// sigma stands for phi in the eq 2.37 p.69
-
-parameters alpha beta delta gamm phi1 eta a b rho  phi2 Psi thetass;  
-//phi1 stands for capital phi in eq.2.68 and 2.69
-//phi2 stands for lowercase phi in eq. 2.66
-
-alpha = 0.36;
-beta = 0.989; 
-gamm = 0.5;
-delta = 0.019;
-phi1 = 2;
-phi2 = 0;
-eta = 1;
-a = 0.95;
-b = 2.56;
-rho = 0.95;
-Psi = 1.47630583;
-thetass = 1.0125;
-
-model;
-
-(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = (a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m)^(-b)+beta*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b)/(1+pi(+1));
-
-Psi*(1-exp(n))^(-eta)/(a*exp(c)^(-b)*(a*exp(c)^(1-b) + (1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y)/exp(n);
-
-(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = beta*exp(R(+1))*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b);
-
-exp(R) = alpha*exp(y)/exp(k(-1)) + 1-delta;
-
-exp(k) = (1-delta)*exp(k(-1))+exp(y)-exp(c);
-
-exp(y) = exp(z)*exp(k(-1))^alpha*exp(n)^(1-alpha);
-
-exp(m) = exp(m(-1))*(u+thetass)/(1+pi);
-
-z = rho*z(-1) + e;
-
-u = gamm*u(-1) + phi2*z(-1) + sigma;
-
-end;
-
-shocks;
-var e; stderr 0.007;
-var sigma;stderr 0.0089;
-end;
-
-
-steady;
-
+var y c k m n R pi z u;
+varexo	e sigma;	 
+// sigma stands for phi in the eq 2.37 p.69
+
+parameters alpha beta delta gamm phi1 eta a b rho  phi2 Psi thetass;  
+//phi1 stands for capital phi in eq.2.68 and 2.69
+//phi2 stands for lowercase phi in eq. 2.66
+
+alpha = 0.36;
+beta = 0.989; 
+gamm = 0.5;
+delta = 0.019;
+phi1 = 2;
+phi2 = 0;
+eta = 1;
+a = 0.95;
+b = 2.56;
+rho = 0.95;
+Psi = 1.47630583;
+thetass = 1.0125;
+
+model;
+
+(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = (a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m)^(-b)+beta*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b)/(1+pi(+1));
+
+Psi*(1-exp(n))^(-eta)/(a*exp(c)^(-b)*(a*exp(c)^(1-b) + (1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y)/exp(n);
+
+(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = beta*exp(R(+1))*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b);
+
+exp(R) = alpha*exp(y)/exp(k(-1)) + 1-delta;
+
+exp(k) = (1-delta)*exp(k(-1))+exp(y)-exp(c);
+
+exp(y) = exp(z)*exp(k(-1))^alpha*exp(n)^(1-alpha);
+
+exp(m) = exp(m(-1))*(u+thetass)/(1+pi);
+
+z = rho*z(-1) + e;
+
+u = gamm*u(-1) + phi2*z(-1) + sigma;
+
+end;
+
+shocks;
+var e; stderr 0.007;
+var sigma;stderr 0.0089;
+end;
+
+
+steady;
+
diff --git a/tests/steady_state/walsh1_ssm.mod b/tests/steady_state/walsh1_ssm.mod
index 8d1de749e0..11ad8da6b5 100644
--- a/tests/steady_state/walsh1_ssm.mod
+++ b/tests/steady_state/walsh1_ssm.mod
@@ -1,72 +1,72 @@
-var y c k m n R pi z u;
-varexo	e sigma;	 
-// sigma stands for phi in the eq 2.37 p.69
-
-parameters alpha beta delta gamm phi1 eta a b rho  phi2 Psi thetass;  
-//phi1 stands for capital phi in eq.2.68 and 2.69
-//phi2 stands for lowercase phi in eq. 2.66
-
-alpha = 0.36;
-beta = 0.989; 
-gamm = 0.5;
-delta = 0.019;
-phi1 = 2;
-phi2 = 0;
-eta = 1;
-a = 0.95;
-b = 2.56;
-rho = 0.95;
-Psi = 1.47630583;
-thetass = 1.0125;
-
-model;
-
-(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = (a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m)^(-b)+beta*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b)/(1+pi(+1));
-
-Psi*(1-exp(n))^(-eta)/(a*exp(c)^(-b)*(a*exp(c)^(1-b) + (1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y)/exp(n);
-
-(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = beta*exp(R(+1))*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b);
-
-exp(R) = alpha*exp(y)/exp(k(-1)) + 1-delta;
-
-exp(k) = (1-delta)*exp(k(-1))+exp(y)-exp(c);
-
-exp(y) = exp(z)*exp(k(-1))^alpha*exp(n)^(1-alpha);
-
-exp(m) = exp(m(-1))*(u+thetass)/(1+pi);
-
-z = rho*z(-1) + e;
-
-u = gamm*u(-1) + phi2*z(-1) + sigma;
-
-end;
-
-shocks;
-var e; stderr 0.007;
-var sigma;stderr 0.0089;
-end;
-
-steady_state_model;
-// solving in levels
-// calibrating n = 1/3 and recovering the value of Psi
-// adapting solution Walsh (2003) p. 84
-pi = thetass-1;
-en = 1/3;
-eR = 1/beta;
-y_k = (1/alpha)*(1/beta-1+delta);
-ek = en*y_k^(-1/(1-alpha));
-ec = ek*(y_k-delta);
-em = ec*(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^(-1/b);
-ey = ek*y_k;
-Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^((b-1)/b));
-Psi = (1-alpha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta;
-n = log(en);
-k = log(ek);
-m = log(em);
-c = log(ec);
-y = log(ey);
-R = log(eR);
-end;
-
-steady;
-
+var y c k m n R pi z u;
+varexo	e sigma;	 
+// sigma stands for phi in the eq 2.37 p.69
+
+parameters alpha beta delta gamm phi1 eta a b rho  phi2 Psi thetass;  
+//phi1 stands for capital phi in eq.2.68 and 2.69
+//phi2 stands for lowercase phi in eq. 2.66
+
+alpha = 0.36;
+beta = 0.989; 
+gamm = 0.5;
+delta = 0.019;
+phi1 = 2;
+phi2 = 0;
+eta = 1;
+a = 0.95;
+b = 2.56;
+rho = 0.95;
+Psi = 1.47630583;
+thetass = 1.0125;
+
+model;
+
+(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = (a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m)^(-b)+beta*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b)/(1+pi(+1));
+
+Psi*(1-exp(n))^(-eta)/(a*exp(c)^(-b)*(a*exp(c)^(1-b) + (1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y)/exp(n);
+
+(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = beta*exp(R(+1))*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b);
+
+exp(R) = alpha*exp(y)/exp(k(-1)) + 1-delta;
+
+exp(k) = (1-delta)*exp(k(-1))+exp(y)-exp(c);
+
+exp(y) = exp(z)*exp(k(-1))^alpha*exp(n)^(1-alpha);
+
+exp(m) = exp(m(-1))*(u+thetass)/(1+pi);
+
+z = rho*z(-1) + e;
+
+u = gamm*u(-1) + phi2*z(-1) + sigma;
+
+end;
+
+shocks;
+var e; stderr 0.007;
+var sigma;stderr 0.0089;
+end;
+
+steady_state_model;
+// solving in levels
+// calibrating n = 1/3 and recovering the value of Psi
+// adapting solution Walsh (2003) p. 84
+pi = thetass-1;
+en = 1/3;
+eR = 1/beta;
+y_k = (1/alpha)*(1/beta-1+delta);
+ek = en*y_k^(-1/(1-alpha));
+ec = ek*(y_k-delta);
+em = ec*(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^(-1/b);
+ey = ek*y_k;
+Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^((b-1)/b));
+Psi = (1-alpha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta;
+n = log(en);
+k = log(ek);
+m = log(em);
+c = log(ec);
+y = log(ey);
+R = log(eR);
+end;
+
+steady;
+
diff --git a/tests/steady_state/walsh1_ssm_block.mod b/tests/steady_state/walsh1_ssm_block.mod
index 05bd181253..38fe294ee6 100644
--- a/tests/steady_state/walsh1_ssm_block.mod
+++ b/tests/steady_state/walsh1_ssm_block.mod
@@ -1,72 +1,72 @@
-var y c k m n R pi z u;
-varexo	e sigma;	 
-// sigma stands for phi in the eq 2.37 p.69
-
-parameters alpha beta delta gamm phi1 eta a b rho  phi2 Psi thetass;  
-//phi1 stands for capital phi in eq.2.68 and 2.69
-//phi2 stands for lowercase phi in eq. 2.66
-
-alpha = 0.36;
-beta = 0.989; 
-gamm = 0.5;
-delta = 0.019;
-phi1 = 2;
-phi2 = 0;
-eta = 1;
-a = 0.95;
-b = 2.56;
-rho = 0.95;
-Psi = 1.47630583;
-thetass = 1.0125;
-
-model(block);
-
-(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = (a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m)^(-b)+beta*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b)/(1+pi(+1));
-
-Psi*(1-exp(n))^(-eta)/(a*exp(c)^(-b)*(a*exp(c)^(1-b) + (1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y)/exp(n);
-
-(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = beta*exp(R(+1))*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b);
-
-exp(R) = alpha*exp(y)/exp(k(-1)) + 1-delta;
-
-exp(k) = (1-delta)*exp(k(-1))+exp(y)-exp(c);
-
-exp(y) = exp(z)*exp(k(-1))^alpha*exp(n)^(1-alpha);
-
-exp(m) = exp(m(-1))*(u+thetass)/(1+pi);
-
-z = rho*z(-1) + e;
-
-u = gamm*u(-1) + phi2*z(-1) + sigma;
-
-end;
-
-shocks;
-var e; stderr 0.007;
-var sigma;stderr 0.0089;
-end;
-
-steady_state_model;
-// solving in levels
-// calibrating n = 1/3 and recovering the value of Psi
-// adapting solution Walsh (2003) p. 84
-pi = thetass-1;
-en = 1/3;
-eR = 1/beta;
-y_k = (1/alpha)*(1/beta-1+delta);
-ek = en*y_k^(-1/(1-alpha));
-ec = ek*(y_k-delta);
-em = ec*(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^(-1/b);
-ey = ek*y_k;
-Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^((b-1)/b));
-Psi = (1-alpha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta;
-n = log(en);
-k = log(ek);
-m = log(em);
-c = log(ec);
-y = log(ey);
-R = log(eR);
-end;
-
-steady;
-
+var y c k m n R pi z u;
+varexo	e sigma;	 
+// sigma stands for phi in the eq 2.37 p.69
+
+parameters alpha beta delta gamm phi1 eta a b rho  phi2 Psi thetass;  
+//phi1 stands for capital phi in eq.2.68 and 2.69
+//phi2 stands for lowercase phi in eq. 2.66
+
+alpha = 0.36;
+beta = 0.989; 
+gamm = 0.5;
+delta = 0.019;
+phi1 = 2;
+phi2 = 0;
+eta = 1;
+a = 0.95;
+b = 2.56;
+rho = 0.95;
+Psi = 1.47630583;
+thetass = 1.0125;
+
+model(block);
+
+(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = (a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*(1-a)*exp(m)^(-b)+beta*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b)/(1+pi(+1));
+
+Psi*(1-exp(n))^(-eta)/(a*exp(c)^(-b)*(a*exp(c)^(1-b) + (1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))) = (1-alpha)*exp(y)/exp(n);
+
+(a*exp(c)^(1-b)+(1-a)*exp(m)^(1-b))^((b-phi1)/(1-b))*a*exp(c)^(-b) = beta*exp(R(+1))*(a*exp(c(+1))^(1-b)+(1-a)*exp(m(+1))^(1-b))^((b-phi1)/(1-b))*a*exp(c(+1))^(-b);
+
+exp(R) = alpha*exp(y)/exp(k(-1)) + 1-delta;
+
+exp(k) = (1-delta)*exp(k(-1))+exp(y)-exp(c);
+
+exp(y) = exp(z)*exp(k(-1))^alpha*exp(n)^(1-alpha);
+
+exp(m) = exp(m(-1))*(u+thetass)/(1+pi);
+
+z = rho*z(-1) + e;
+
+u = gamm*u(-1) + phi2*z(-1) + sigma;
+
+end;
+
+shocks;
+var e; stderr 0.007;
+var sigma;stderr 0.0089;
+end;
+
+steady_state_model;
+// solving in levels
+// calibrating n = 1/3 and recovering the value of Psi
+// adapting solution Walsh (2003) p. 84
+pi = thetass-1;
+en = 1/3;
+eR = 1/beta;
+y_k = (1/alpha)*(1/beta-1+delta);
+ek = en*y_k^(-1/(1-alpha));
+ec = ek*(y_k-delta);
+em = ec*(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^(-1/b);
+ey = ek*y_k;
+Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-beta)/thetass)^((b-1)/b));
+Psi = (1-alpha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta;
+n = log(en);
+k = log(ek);
+m = log(em);
+c = log(ec);
+y = log(ey);
+R = log(eR);
+end;
+
+steady;
+
diff --git a/tests/test.m b/tests/test.m
index f05f5f1c45..a23db43112 100644
--- a/tests/test.m
+++ b/tests/test.m
@@ -1,4 +1,4 @@
-function test(a,b,n)
-  if max(max(abs(a)-abs(b))) > 1e-5
-    error(['Test error in test ' int2str(n)])
+function test(a,b,n)
+  if max(max(abs(a)-abs(b))) > 1e-5
+    error(['Test error in test ' int2str(n)])
   end
\ No newline at end of file
-- 
GitLab