1function model_info(varargin) 2%function model_info; 3 4% Copyright (C) 2008-2018 Dynare Team 5% 6% This file is part of Dynare. 7% 8% Dynare is free software: you can redistribute it and/or modify 9% it under the terms of the GNU General Public License as published by 10% the Free Software Foundation, either version 3 of the License, or 11% (at your option) any later version. 12% 13% Dynare is distributed in the hope that it will be useful, 14% but WITHOUT ANY WARRANTY; without even the implied warranty of 15% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16% GNU General Public License for more details. 17% 18% You should have received a copy of the GNU General Public License 19% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 20 21global M_; 22if sum(strcmp(varargin,'static')) > 0 23 static_ = 1; 24else 25 static_ = 0; 26end 27if sum(strcmp(varargin,'incidence')) > 0 28 incidence = 1; 29else 30 incidence = 0; 31end 32if static_ 33 fprintf(' Informations about %s (static model)\n',M_.fname); 34 block_structre_str = 'block_structure_stat'; 35 nb_leadlag = 1; 36else 37 fprintf(' Informations about %s (dynamic model)\n',M_.fname); 38 block_structre_str = 'block_structure'; 39 nb_leadlag = 3; 40end 41if(isfield(M_,block_structre_str)) 42 if static_ 43 block_structure = M_.block_structure_stat; 44 else 45 block_structure = M_.block_structure; 46 end 47 fprintf(strcat(' ===================',char(ones(1,length(M_.fname))*'='),'\n\n')); 48 nb_blocks=length(block_structure.block); 49 fprintf('The model has %d equations and is decomposed in %d blocks as follow:\n',M_.endo_nbr,nb_blocks); 50 fprintf('===============================================================================================================\n'); 51 fprintf('| %10s | %10s | %30s | %14s | %31s |\n','Block no','Size','Block Type',' Equation','Dependent variable'); 52 fprintf('|============|============|================================|================|=================================|\n'); 53 for i=1:nb_blocks 54 size_block=length(block_structure.block(i).equation); 55 if(i>1) 56 fprintf('|------------|------------|--------------------------------|----------------|---------------------------------|\n'); 57 end 58 for j=1:size_block 59 if(j==1) 60 fprintf('| %10d | %10d | %30s | %14d | %-6d %24s |\n',i,size_block,Sym_type(block_structure.block(i).Simulation_Type),block_structure.block(i).equation(j),block_structure.block(i).variable(j),M_.endo_names{block_structure.block(i).variable(j)}); 61 else 62 fprintf('| %10s | %10s | %30s | %14d | %-6d %24s |\n','','','',block_structure.block(i).equation(j),block_structure.block(i).variable(j),M_.endo_names{block_structure.block(i).variable(j)}); 63 end 64 end 65 end 66 fprintf('===============================================================================================================\n'); 67 fprintf('\n'); 68 if static_ 69 fprintf('%-30s %s','the variable','is used in equations Contemporaneously'); 70 if(size(block_structure.incidence.sparse_IM,1)>0) 71 IM=sortrows(block_structure.incidence.sparse_IM,2); 72 else 73 IM=[]; 74 end 75 size_IM=size(IM,1); 76 last=99999999; 77 for i=1:size_IM 78 if(last~=IM(i,2)) 79 fprintf('\n%-30s',M_.endo_names{IM(i,2)}); 80 end 81 fprintf(' %5d',IM(i,1)); 82 last=IM(i,2); 83 end 84 fprintf('\n\n'); 85 else 86 for k=1:M_.maximum_endo_lag+M_.maximum_endo_lead+1 87 if(k==M_.maximum_endo_lag+1) 88 fprintf('%-30s %s','the variable','is used in equations Contemporaneously'); 89 elseif(k<M_.maximum_endo_lag+1) 90 fprintf('%-30s %s %d','the variable','is used in equations with lag ',M_.maximum_endo_lag+1-k); 91 else 92 fprintf('%-30s %s %d','the variable','is used in equations with lead ',k-(M_.maximum_endo_lag+1)); 93 end 94 if(size(block_structure.incidence(k).sparse_IM,1)>0) 95 IM=sortrows(block_structure.incidence(k).sparse_IM,2); 96 else 97 IM=[]; 98 end 99 size_IM=size(IM,1); 100 last=99999999; 101 for i=1:size_IM 102 if(last~=IM(i,2)) 103 fprintf('\n%-30s',M_.endo_names{IM(i,2)}); 104 end 105 fprintf(' %5d',IM(i,1)); 106 last=IM(i,2); 107 end 108 fprintf('\n\n'); 109 end 110 end 111 112 %printing the gross incidence matrix 113 IM_star = char([kron(ones(M_.endo_nbr, M_.endo_nbr-1), double(blanks(3))) double(blanks(M_.endo_nbr)')]); 114 for i = 1:nb_leadlag 115 n = size(block_structure.incidence(i).sparse_IM,1); 116 for j = 1:n 117 if ismember(block_structure.incidence(i).sparse_IM(j,2), M_.state_var) 118 IM_star(block_structure.incidence(i).sparse_IM(j,1), 3 * (block_structure.incidence(i).sparse_IM(j,2) - 1) + 1) = 'X'; 119 else 120 IM_star(block_structure.incidence(i).sparse_IM(j,1), 3 * (block_structure.incidence(i).sparse_IM(j,2) - 1) + 1) = '1'; 121 end 122 end 123 end 124 seq = 1: M_.endo_nbr; 125 blank = [ blanks(cellofchararraymaxlength(M_.endo_names)); blanks(cellofchararraymaxlength(M_.endo_names))]; 126 for i = 1:M_.endo_nbr 127 if i == 1 128 var_names = char(blank, M_.endo_names{i}); 129 else 130 var_names = char(var_names, blank, M_.endo_names{i}); 131 end 132 end 133 if incidence 134 topp = [char(kron(double(blanks(ceil(log10(M_.endo_nbr)))),ones(cellofchararraymaxlength(M_.endo_names),1))) var_names' ]; 135 bott = [int2str(seq') blanks(M_.endo_nbr)' blanks(M_.endo_nbr)' IM_star]; 136 fprintf('\n Gross incidence matrix\n'); 137 fprintf(' =======================\n'); 138 disp([topp; bott]); 139 140 %printing the reordered incidence matrix 141 IM_star_reordered = char([kron(ones(M_.endo_nbr, M_.endo_nbr-1), double(blanks(3))) double(blanks(M_.endo_nbr)')]); 142 eq(block_structure.equation_reordered) = seq; 143 va(block_structure.variable_reordered) = seq; 144 barre_blank = [ barre(cellofchararraymaxlength(M_.endo_names)); blanks(cellofchararraymaxlength(M_.endo_names))]; 145 cur_block = 1; 146 for i = 1:M_.endo_nbr 147 past_block = cur_block; 148 while ismember(block_structure.variable_reordered(i), block_structure.block(cur_block).variable) == 0 149 cur_block = cur_block + 1; 150 end 151 if i == 1 152 var_names = [blank; M_.endo_names{block_structure.variable_reordered(i)}]; 153 else 154 if past_block ~= cur_block 155 var_names = [var_names; barre_blank; M_.endo_names{block_structure.variable_reordered(i)}]; 156 else 157 var_names = [var_names; blank; M_.endo_names{block_structure.variable_reordered(i)}]; 158 end 159 end 160 end 161 topp = [char(kron(double(blanks(ceil(log10(M_.endo_nbr)))),ones(cellofchararraymaxlength(M_.endo_names),1))) var_names' ]; 162 n_state_var = length(M_.state_var); 163 IM_state_var = zeros(n_state_var, n_state_var); 164 inv_variable_reordered(block_structure.variable_reordered) = 1:M_.endo_nbr; 165 state_equation = block_structure.equation_reordered(inv_variable_reordered(M_.state_var)); 166 for i = 1:nb_leadlag 167 n = size(block_structure.incidence(i).sparse_IM,1); 168 for j = 1:n 169 [tf, loc] = ismember(block_structure.incidence(i).sparse_IM(j,2), M_.state_var); 170 if tf 171 IM_star_reordered(eq(block_structure.incidence(i).sparse_IM(j,1)), 3 * (va(block_structure.incidence(i).sparse_IM(j,2)) - 1) + 1) = 'X'; 172 [tfi, loci] = ismember(block_structure.incidence(i).sparse_IM(j,1), state_equation); 173 if tfi 174 IM_state_var(loci, loc) = 1; 175 end 176 else 177 IM_star_reordered(eq(block_structure.incidence(i).sparse_IM(j,1)), 3 * (va(block_structure.incidence(i).sparse_IM(j,2)) - 1) + 1) = '1'; 178 end 179 end 180 end 181 fprintf('1: non nul element, X: non nul element related to a state variable\n'); 182 183 cur_block = 1; 184 i_last = 0; 185 block = {}; 186 for i = 1:n_state_var 187 past_block = cur_block; 188 while ismember(M_.state_var(i), block_structure.block(cur_block).variable) == 0 189 cur_block = cur_block + 1; 190 end 191 if (past_block ~= cur_block) || (past_block == cur_block && i == n_state_var) 192 block(past_block).IM_state_var(1:(i - 1 - i_last), 1:i - 1) = IM_state_var(i_last+1:i - 1, 1:i - 1); 193 i_last = i - 1; 194 end 195 end 196 cur_block = 1; 197 for i = 1:M_.endo_nbr 198 past_block = cur_block; 199 while ismember(block_structure.variable_reordered(i), block_structure.block(cur_block).variable) == 0 200 cur_block = cur_block + 1; 201 end 202 if past_block ~= cur_block 203 for j = 1:i-1 204 IM_star_reordered(j, 3 * (i - 1) - 1) = '|'; 205 end 206 end 207 end 208 209 bott = [int2str(block_structure.equation_reordered') blanks(M_.endo_nbr)' blanks(M_.endo_nbr)' IM_star_reordered]; 210 fprintf('\n Reordered incidence matrix\n'); 211 fprintf(' ==========================\n'); 212 disp([topp; bott]); 213 fprintf('1: non nul element, X: non nul element related to a state variable\n'); 214 end 215else 216 fprintf('There is no block decomposition of the model.\nUse ''block'' model''s option.\n'); 217end 218 219function ret=Sym_type(type) 220UNKNOWN=0; 221EVALUATE_FORWARD=1; 222EVALUATE_BACKWARD=2; 223SOLVE_FORWARD_SIMPLE=3; 224SOLVE_BACKWARD_SIMPLE=4; 225SOLVE_TWO_BOUNDARIES_SIMPLE=5; 226SOLVE_FORWARD_COMPLETE=6; 227SOLVE_BACKWARD_COMPLETE=7; 228SOLVE_TWO_BOUNDARIES_COMPLETE=8; 229EVALUATE_FORWARD_R=9; 230EVALUATE_BACKWARD_R=10; 231switch (type) 232 case (UNKNOWN) 233 ret='UNKNOWN '; 234 case {EVALUATE_FORWARD,EVALUATE_FORWARD_R} 235 ret='EVALUATE FORWARD '; 236 case {EVALUATE_BACKWARD,EVALUATE_BACKWARD_R} 237 ret='EVALUATE BACKWARD '; 238 case SOLVE_FORWARD_SIMPLE 239 ret='SOLVE FORWARD SIMPLE '; 240 case SOLVE_BACKWARD_SIMPLE 241 ret='SOLVE BACKWARD SIMPLE '; 242 case SOLVE_TWO_BOUNDARIES_SIMPLE 243 ret='SOLVE TWO BOUNDARIES SIMPLE '; 244 case SOLVE_FORWARD_COMPLETE 245 ret='SOLVE FORWARD COMPLETE '; 246 case SOLVE_BACKWARD_COMPLETE 247 ret='SOLVE BACKWARD COMPLETE '; 248 case SOLVE_TWO_BOUNDARIES_COMPLETE 249 ret='SOLVE TWO BOUNDARIES COMPLETE'; 250end 251 252 253function ret = barre(n) 254s = []; 255for i=1:n 256 s = [s '|']; 257end 258ret = s; 259