From 5f6946a1b9304e33f30b1acaaf69f82d3d21e82d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 25 Oct 2022 12:27:20 +0200
Subject: [PATCH] =?UTF-8?q?Display=20equation=20names=20in=20=E2=80=9Cmode?=
 =?UTF-8?q?l=5Finfo=E2=80=9D=20command?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 matlab/get_equation_name_by_number.m | 28 ++++++++++++++++++++++++++++
 matlab/model_info.m                  | 14 +++++++-------
 2 files changed, 35 insertions(+), 7 deletions(-)
 create mode 100644 matlab/get_equation_name_by_number.m

diff --git a/matlab/get_equation_name_by_number.m b/matlab/get_equation_name_by_number.m
new file mode 100644
index 0000000000..11f9888474
--- /dev/null
+++ b/matlab/get_equation_name_by_number.m
@@ -0,0 +1,28 @@
+function eqname = get_equation_name_by_number(eqnumber, M_)
+% Returns the name of an equation given its number
+
+% Copyright © 2022 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 <https://www.gnu.org/licenses/>.
+
+idx_for_this_eq = find(cell2mat(M_.equations_tags(:,1)) == eqnumber);
+eqname = cell2mat(M_.equations_tags(idx_for_this_eq(strmatch('name', M_.equations_tags(idx_for_this_eq, 2), 'exact')), 3));
+
+if isempty(eqname)
+    eqname = '';
+end
+
+end
diff --git a/matlab/model_info.m b/matlab/model_info.m
index 8be10ddf45..5744a45f9f 100644
--- a/matlab/model_info.m
+++ b/matlab/model_info.m
@@ -43,23 +43,23 @@ if isfield(M_,block_structre_str)
     fprintf(strcat('                                          ===================',char(ones(1,length(M_.fname))*'='),'\n\n'));
     nb_blocks=length(block_structure.block);
     fprintf('The model has %d equations and is decomposed in %d blocks as follow:\n',M_.endo_nbr,nb_blocks);
-    fprintf('===============================================================================================================\n');
-    fprintf('| %10s | %10s | %30s | %14s | %31s |\n','Block no','Size','Block Type','   Equation','Dependent variable');
-    fprintf('|============|============|================================|================|=================================|\n');
+    fprintf('================================================================================================================================\n');
+    fprintf('| %10s | %10s | %30s | %31s | %31s |\n','Block no','Size','Block Type','Equation','Dependent variable');
+    fprintf('|============|============|================================|=================================|=================================|\n');
     for i=1:nb_blocks
         size_block=length(block_structure.block(i).equation);
         if(i>1)
-            fprintf('|------------|------------|--------------------------------|----------------|---------------------------------|\n');
+            fprintf('|------------|------------|--------------------------------|---------------------------------|---------------------------------|\n');
         end
         for j=1:size_block
             if(j==1)
-                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)});
+                fprintf('| %10d | %10d | %30s | %-6d %24s | %-6d %24s |\n',i,size_block,Sym_type(block_structure.block(i).Simulation_Type),block_structure.block(i).equation(j),get_equation_name_by_number(block_structure.block(i).equation(j), M_),block_structure.block(i).variable(j),M_.endo_names{block_structure.block(i).variable(j)});
             else
-                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)});
+                fprintf('| %10s | %10s | %30s | %-6d %24s | %-6d %24s |\n','','','',block_structure.block(i).equation(j),get_equation_name_by_number(block_structure.block(i).equation(j), M_),block_structure.block(i).variable(j),M_.endo_names{block_structure.block(i).variable(j)});
             end
         end
     end
-    fprintf('===============================================================================================================\n');
+    fprintf('================================================================================================================================\n');
     fprintf('\n');
     if static_
         fprintf('%-30s %s','the variable','is used in the following equations contemporaneously');
-- 
GitLab