From 3afc670794921b22a18b04bb80b92004d9067df8 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Fri, 14 Feb 2014 16:18:05 +0100
Subject: [PATCH] reporting: for easier figure reference, by default save
 report figures as: pg%d_sec%d_row%d_col%d.tex

---
 matlab/reports/@graph/write.m          | 10 +++++++---
 matlab/reports/@graph/writeGraphFile.m | 16 ++++++++--------
 matlab/reports/@page/write.m           |  7 ++++---
 matlab/reports/@report/write.m         |  2 +-
 matlab/reports/@report_table/write.m   |  4 ++--
 matlab/reports/@section/write.m        | 18 ++++++++++++------
 6 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/matlab/reports/@graph/write.m b/matlab/reports/@graph/write.m
index 7fee076f3a..4c4936672b 100644
--- a/matlab/reports/@graph/write.m
+++ b/matlab/reports/@graph/write.m
@@ -1,10 +1,14 @@
-function o = write(o, fid)
-%function o = write(o, fid)
+function o = write(o, fid, pg, sec, row, col)
+%function o = write(o, fid, pg, sec, row, col)
 % Write a Graph object
 %
 % INPUTS
 %   o   [graph]   graph object
 %   fid [integer] file id
+%   pg  [integer] this page number
+%   sec [integer] this section number
+%   row [integer] this row number
+%   col [integer] this col number
 %
 % OUTPUTS
 %   o   [graph] graph object
@@ -30,6 +34,6 @@ function o = write(o, fid)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 assert(fid ~= -1);
-o = writeGraphFile(o);
+o = writeGraphFile(o, pg, sec, row, col);
 fprintf(fid, '\\input{%s}', o.figname);
 end
\ No newline at end of file
diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m
index d130f8d613..57528abf76 100644
--- a/matlab/reports/@graph/writeGraphFile.m
+++ b/matlab/reports/@graph/writeGraphFile.m
@@ -1,9 +1,13 @@
-function o = writeGraphFile(o)
-%function o = writeGraphFile(o)
+function o = writeGraphFile(o, pg, sec, row, col)
+%function o = writeGraphFile(o, pg, sec, row, col)
 % Write the tikz file that contains the graph
 %
 % INPUTS
-%   o   [graph] graph object
+%   o   [graph]   graph object
+%   pg  [integer] this page number
+%   sec [integer] this section number
+%   row [integer] this row number
+%   col [integer] this col number
 %
 % OUTPUTS
 %   o   [graph] graph object
@@ -35,11 +39,7 @@ if ne < 1
 end
 
 if isempty(o.figname)
-    [junk, tn] = fileparts(tempname);
-    if strcmp(computer, 'PCWIN') || strcmp(computer, 'PCWIN64')
-        tn = strrep(tn, '_', '-');
-    end
-    o.figname = [o.figDirName '/' tn '.tex'];
+    o.figname = sprintf('%s/pg%d_sec%d_row%d_col%d.tex', o.figDirName, pg, sec, row, col);
 end
 
 [fid, msg] = fopen(o.figname, 'w');
diff --git a/matlab/reports/@page/write.m b/matlab/reports/@page/write.m
index c8bd3c0402..274cf3c2c0 100644
--- a/matlab/reports/@page/write.m
+++ b/matlab/reports/@page/write.m
@@ -1,10 +1,11 @@
-function o = write(o, fid)
-%function o = write(o, fid)
+function o = write(o, fid, pg)
+%function o = write(o, fid, pg)
 % Write a Page object
 %
 % INPUTS
 %   o              [page]     page object
 %   fid            [integer]  file id
+%   pg             [integer]  this page number
 %
 % OUTPUTS
 %   o              [page]     page object
@@ -48,7 +49,7 @@ end
 
 nps = length(o.sections);
 for i=1:nps
-    o.sections{i}.write(fid);
+    o.sections{i}.write(fid, pg, i);
 end
 
 if strcmpi(o.orientation, 'landscape')
diff --git a/matlab/reports/@report/write.m b/matlab/reports/@report/write.m
index fd6efceabd..c2016f8622 100644
--- a/matlab/reports/@report/write.m
+++ b/matlab/reports/@report/write.m
@@ -80,7 +80,7 @@ fprintf(fid, '\\centering\n');
 nps = length(o.pages);
 for i=1:nps
     fprintf(1, 'Writing Page: %d\n', i);
-    o.pages{i}.write(fid);
+    o.pages{i}.write(fid, i);
 end
 
 fprintf(fid, '\\end{document}\n');
diff --git a/matlab/reports/@report_table/write.m b/matlab/reports/@report_table/write.m
index 4460e5d3f2..5a97362f35 100644
--- a/matlab/reports/@report_table/write.m
+++ b/matlab/reports/@report_table/write.m
@@ -1,5 +1,5 @@
-function o = write(o, fid)
-%function o = write(o, fid)
+function o = write(o, fid, pg, sec, row, col)
+%function o = write(o, fid, pg, sec, row, col)
 % Write a Report_Table object
 %
 % INPUTS
diff --git a/matlab/reports/@section/write.m b/matlab/reports/@section/write.m
index 4055dd6f72..888e7a9f02 100644
--- a/matlab/reports/@section/write.m
+++ b/matlab/reports/@section/write.m
@@ -1,10 +1,12 @@
-function o = write(o, fid)
-%function o = write(o, fid)
+function o = write(o, fid, pg, sec)
+%function o = write(o, fid, pg, sec)
 % Write Section object
 %
 % INPUTS
 %   o         [section] section object
 %   fid       [integer] file id
+%   pg        [integer] this page number
+%   sec       [integer] this section number
 %
 % OUTPUTS
 %   o         [section] section object
@@ -48,20 +50,24 @@ end
 fprintf(fid, '}\n');
 ne = numElements(o);
 nlcounter = 0;
+row = 1;
+col = 1;
 for i=1:ne
     if isa(o.elements{i}, 'vspace')
-        assert(rem(nlcounter, o.cols) == 0, ['@section.write: must place ' ...
+        assert(col == o.cols, ['@section.write: must place ' ...
                             'vspace command after a linebreak in the table ' ...
                             'or series of charts']);
         o.elements{i}.write(fid);
         fprintf(fid, '\\\\\n');
     else
-        o.elements{i}.write(fid);
-        nlcounter = nlcounter + 1;
-        if rem(nlcounter, o.cols)
+        o.elements{i}.write(fid, pg, sec, row, col);
+        if col ~= o.cols
             fprintf(fid, ' & ');
+            col = col + 1;
         else
             fprintf(fid, '\\\\\n');
+            row = row + 1;
+            col = 1;
         end
     end
 end
-- 
GitLab