wolffd@0
|
1 function aout = rep_utils(action,fmt,fid)
|
wolffd@0
|
2
|
wolffd@0
|
3 %REP_UTILS Utilities for print reports and report elements.
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % aout = rep_utils(action,fmt,[fid])
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % Input and output arguments ([]'s are optional):
|
wolffd@0
|
8 % action (string) action identifier
|
wolffd@0
|
9 % (cell array) {action,par1,par2,...}
|
wolffd@0
|
10 % the action identifier, followed by action
|
wolffd@0
|
11 % parameters
|
wolffd@0
|
12 % [fmt] (string) format of output, 'txt' by default
|
wolffd@0
|
13 % [fid] (scalar) output file id, by default NaN in which
|
wolffd@0
|
14 % case output is not written, only returned
|
wolffd@0
|
15 % in aout
|
wolffd@0
|
16 %
|
wolffd@0
|
17 % aout (varies) output of the action
|
wolffd@0
|
18 %
|
wolffd@0
|
19 % Here are the actions and their arguments:
|
wolffd@0
|
20 % 'printlines' par1 (cellstr) print par1, each cell on a new line
|
wolffd@0
|
21 % 'header' par1 (string) print document header using par1 as title
|
wolffd@0
|
22 % 'footer' print document footer
|
wolffd@0
|
23 % 'compile' par1 (string) compile the named document (only 'ps' and 'pdf')
|
wolffd@0
|
24 % 'inserttable' par1 (struct) print given table
|
wolffd@0
|
25 % par2 (scalar) print lines between rows if par2=1
|
wolffd@0
|
26 % par3 (scalar) use longtable format (only 'ps' and 'pdf')
|
wolffd@0
|
27 % 'printfigure' par1 (string) print current figure to file, par1 = filename
|
wolffd@0
|
28 % par2 (scalar) used resolution (150 dpi by default)
|
wolffd@0
|
29 % par3 (scalar) if par3=1, insert figure in minipage
|
wolffd@0
|
30 % 'insertfigure' par1 (string) insert figure to report, par1 = filename of figure
|
wolffd@0
|
31 % par2 (vector) size 2 x 1, size of figure relative to page size
|
wolffd@0
|
32 % NaN = automatic scaling
|
wolffd@0
|
33 % par3 (scalar) if par3=1, insert figure in minipage (only 'ps' and 'pdf')
|
wolffd@0
|
34 % 'insertbreak' insert paragraph break into report
|
wolffd@0
|
35 %
|
wolffd@0
|
36 % See also REP_STATS.
|
wolffd@0
|
37
|
wolffd@0
|
38 % Contributed to SOM Toolbox 2.0, January 2nd, 2002 by Juha Vesanto
|
wolffd@0
|
39 % Copyright (c) by Juha Vesanto
|
wolffd@0
|
40 % http://www.cis.hut.fi/projects/somtoolbox/
|
wolffd@0
|
41
|
wolffd@0
|
42 % Version 2.0beta juuso 020102
|
wolffd@0
|
43
|
wolffd@0
|
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
45 %% input arguments
|
wolffd@0
|
46
|
wolffd@0
|
47 pars = {''};
|
wolffd@0
|
48 if iscell(action),
|
wolffd@0
|
49 if length(action)>1, pars = action(2:end); end
|
wolffd@0
|
50 action = action{1};
|
wolffd@0
|
51 end
|
wolffd@0
|
52
|
wolffd@0
|
53 if nargin<2 | isempty(fmt), fmt = 'txt'; end
|
wolffd@0
|
54 global REPORT_OUTPUT_FMT
|
wolffd@0
|
55 REPORT_OUTPUT_FMT = fmt;
|
wolffd@0
|
56
|
wolffd@0
|
57 if nargin<3 | isempty(fid), fid = NaN; end
|
wolffd@0
|
58
|
wolffd@0
|
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
60 %% action
|
wolffd@0
|
61
|
wolffd@0
|
62 aout = [];
|
wolffd@0
|
63 printable = 0;
|
wolffd@0
|
64
|
wolffd@0
|
65 switch action,
|
wolffd@0
|
66 case 'printlines',
|
wolffd@0
|
67 aout = pars{1};
|
wolffd@0
|
68 case 'header',
|
wolffd@0
|
69 switch fmt,
|
wolffd@0
|
70 case {'ps','pdf'}, aout = tex_startdocument(pars{1});
|
wolffd@0
|
71 case 'html', aout = html_startpage(pars{1});
|
wolffd@0
|
72 case 'txt', aout = cell(0);
|
wolffd@0
|
73 end
|
wolffd@0
|
74 printable = 1;
|
wolffd@0
|
75 case 'footer',
|
wolffd@0
|
76 switch fmt,
|
wolffd@0
|
77 case {'ps','pdf'}, aout = tex_enddocument;
|
wolffd@0
|
78 case 'html', aout = html_endpage;
|
wolffd@0
|
79 case 'txt', aout = cell(0);
|
wolffd@0
|
80 end
|
wolffd@0
|
81 printable = 1;
|
wolffd@0
|
82 case 'compile', aout = compiledocument(pars{1});
|
wolffd@0
|
83 case 'inserttable', aout = inserttable(pars{:}); printable = 1;
|
wolffd@0
|
84 case 'printfigure', printfigure(pars{:});
|
wolffd@0
|
85 case 'insertfigure', aout = insertfigure(pars{:}); printable = 1;
|
wolffd@0
|
86 case 'insertbreak', aout = insertbreak; printable = 1;
|
wolffd@0
|
87 case 'joinstr', aout = joinstr(pars{:}); printable = 1;
|
wolffd@0
|
88 case 'rulestr', aout = rulestr(pars{:}); printable = 1;
|
wolffd@0
|
89 case 'c_and_p_str', aout = c_and_p_str(pars{:}); printable = 1;
|
wolffd@0
|
90 case 'p_str', aout = p_str(pars{:}); printable = 1;
|
wolffd@0
|
91 end
|
wolffd@0
|
92
|
wolffd@0
|
93 % if output file is given, print lines
|
wolffd@0
|
94 if ~isnan(fid) & printable,
|
wolffd@0
|
95 if ~iscell(aout), aout = {aout}; end
|
wolffd@0
|
96 for i = 1:length(aout), fprintf(fid,'%s\n',fmtline(aout{i})); end
|
wolffd@0
|
97 end
|
wolffd@0
|
98
|
wolffd@0
|
99 return;
|
wolffd@0
|
100
|
wolffd@0
|
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
102 %% subfunctions
|
wolffd@0
|
103
|
wolffd@0
|
104 %% simple formatter strings
|
wolffd@0
|
105
|
wolffd@0
|
106 function s = joinstr(cs, sep1, sep2)
|
wolffd@0
|
107 if nargin==1, sep1 = ', '; sep2 = ' and '; end
|
wolffd@0
|
108 if nargin<3, sep2 = sep1; end
|
wolffd@0
|
109 if isempty(cs),
|
wolffd@0
|
110 s = '';
|
wolffd@0
|
111 elseif strcmp(sep1,'\n'),
|
wolffd@0
|
112 if size(cs,1)==1, cs = cs'; end
|
wolffd@0
|
113 s = char(cs);
|
wolffd@0
|
114 else
|
wolffd@0
|
115 s = cs{1};
|
wolffd@0
|
116 for i=2:length(cs)-1, s = [s sep1 cs{i}]; end
|
wolffd@0
|
117 if length(cs)>1, s = [s sep2 cs{end}]; end
|
wolffd@0
|
118 end
|
wolffd@0
|
119 return;
|
wolffd@0
|
120
|
wolffd@0
|
121 function str = c_and_p_str(n,m)
|
wolffd@0
|
122
|
wolffd@0
|
123 % return a string of form # (%), e.g. '23 (12%)'
|
wolffd@0
|
124 if n==m, p = '100';
|
wolffd@0
|
125 elseif n==0, p = '0';
|
wolffd@0
|
126 else p = sprintf('%.2g',100*n/m);
|
wolffd@0
|
127 end
|
wolffd@0
|
128 str = sprintf('%d (%s%%)',round(n),p);
|
wolffd@0
|
129 return;
|
wolffd@0
|
130
|
wolffd@0
|
131 function str = p_str(p)
|
wolffd@0
|
132 % return a string of form %, e.g. '12%'
|
wolffd@0
|
133 if round(p*100)>=100, p = sprintf('%3g',100*p);
|
wolffd@0
|
134 elseif abs(p)<eps, p = '0';
|
wolffd@0
|
135 else p = sprintf('%.2g',100*p);
|
wolffd@0
|
136 end
|
wolffd@0
|
137 str = sprintf('%s%%',p);
|
wolffd@0
|
138 return;
|
wolffd@0
|
139
|
wolffd@0
|
140 function cs = rulestr(sR,cnames)
|
wolffd@0
|
141 global REPORT_OUTPUT_FMT
|
wolffd@0
|
142 switch REPORT_OUTPUT_FMT
|
wolffd@0
|
143 case {'ps','pdf'}, [leq,geq,infi,m,less,in] = deal('\leq','\geq','\inf','$','<','\in');
|
wolffd@0
|
144 case 'html', [leq,geq,infi,m,less,in] = deal('<=','>=','Inf',' ','<',' ');
|
wolffd@0
|
145 case 'txt', [leq,geq,infi,m,less,in] = deal('<=','>=','inf',' ','<','');
|
wolffd@0
|
146 end
|
wolffd@0
|
147 nr = length(sR);
|
wolffd@0
|
148 cs = cell(nr,1);
|
wolffd@0
|
149 fmt = '%.2g';
|
wolffd@0
|
150 if nargin<2, cnames = {sR.name}; end
|
wolffd@0
|
151 if isempty(cnames), cnames = cell(nr,1); cnames(:) = {''}; end
|
wolffd@0
|
152 for i=1:nr,
|
wolffd@0
|
153 low = sR(i).low;
|
wolffd@0
|
154 high = sR(i).high;
|
wolffd@0
|
155 switch isfinite(low) + 2*isfinite(high),
|
wolffd@0
|
156 case 0, cs{i} = [cnames{i} ' ' 'any'];
|
wolffd@0
|
157 case 1, cs{i} = [cnames{i} ' ' m geq sprintf(fmt,low) m];
|
wolffd@0
|
158 case 2, cs{i} = [cnames{i} ' ' m less sprintf(fmt,high) m];
|
wolffd@0
|
159 case 3, cs{i} = [cnames{i} ' ' m in '[' sprintf(fmt,low) ',' sprintf(fmt,high) ']' m];
|
wolffd@0
|
160 end
|
wolffd@0
|
161 end
|
wolffd@0
|
162 return;
|
wolffd@0
|
163
|
wolffd@0
|
164 %% print figure
|
wolffd@0
|
165
|
wolffd@0
|
166 function imgfmt = fmt2imgfmt
|
wolffd@0
|
167 global REPORT_OUTPUT_FMT
|
wolffd@0
|
168 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
169 case 'ps', imgfmt = 'ps';
|
wolffd@0
|
170 case 'pdf', imgfmt = 'pdf';
|
wolffd@0
|
171 case 'html', imgfmt = 'png';
|
wolffd@0
|
172 case 'txt', imgfmt = '';
|
wolffd@0
|
173 end
|
wolffd@0
|
174 return;
|
wolffd@0
|
175
|
wolffd@0
|
176 function printfigure(fname,resolution)
|
wolffd@0
|
177 if nargin<2, resolution = 150; end
|
wolffd@0
|
178 fnameps = [fname '.ps'];
|
wolffd@0
|
179 switch fmt2imgfmt,
|
wolffd@0
|
180 case 'ps',
|
wolffd@0
|
181 print('-dpsc2',fnameps);
|
wolffd@0
|
182 case 'pdf',
|
wolffd@0
|
183 print('-dpsc2',fnameps);
|
wolffd@0
|
184 eval(sprintf('!ps2pdf %s',fnameps));
|
wolffd@0
|
185 case 'gif',
|
wolffd@0
|
186 print('-dpsc2',fnameps);
|
wolffd@0
|
187 cmd = 'pstogif';
|
wolffd@0
|
188 opt = sprintf('-depth 1 -density %d',resolution);
|
wolffd@0
|
189 unix(sprintf('%s %s -out %s %s',cmd,opt,[fname '.gif'],fnameps));
|
wolffd@0
|
190 case 'png',
|
wolffd@0
|
191 opt = sprintf('-r%d',resolution);
|
wolffd@0
|
192 print('-dpng',opt,[fname '.png']);
|
wolffd@0
|
193 end
|
wolffd@0
|
194 return;
|
wolffd@0
|
195
|
wolffd@0
|
196 %% headers and footers, and compilation
|
wolffd@0
|
197
|
wolffd@0
|
198 function cs = tex_startdocument(title)
|
wolffd@0
|
199 % tex document headers
|
wolffd@0
|
200 global REPORT_OUTPUT_FMT
|
wolffd@0
|
201 cs = cell(0);
|
wolffd@0
|
202 cs{end+1} = '\documentclass[10pt,a4paper]{article}';
|
wolffd@0
|
203 cs{end+1} = '\usepackage[dvips]{epsfig,graphicx,color}';
|
wolffd@0
|
204 cs{end+1} = '\usepackage{float,graphics,subfigure}';
|
wolffd@0
|
205 cs{end+1} = '\usepackage{multirow,rotating,portland,lscape,longtable,pifont}';
|
wolffd@0
|
206 cs{end+1} = '\usepackage[T1]{fontenc}';
|
wolffd@0
|
207 if strcmp(REPORT_OUTPUT_FMT,'pdf'), cs{end+1} = '\usepackage{pslatex}'; end
|
wolffd@0
|
208 cs{end+1} = '\usepackage[english]{babel}';
|
wolffd@0
|
209
|
wolffd@0
|
210 cs{end+1} = '\oddsidemargin 0 mm';
|
wolffd@0
|
211 cs{end+1} = '\evensidemargin 0 mm';
|
wolffd@0
|
212 cs{end+1} = '\textwidth 17 cm';
|
wolffd@0
|
213 cs{end+1} = '\topmargin 0 mm';
|
wolffd@0
|
214 cs{end+1} = '\textheight 21 cm';
|
wolffd@0
|
215 cs{end+1} = '\voffset 0 mm';
|
wolffd@0
|
216
|
wolffd@0
|
217 cs{end+1} = '\begin{document}';
|
wolffd@0
|
218 cs{end+1} = ['\title{' title '}'];
|
wolffd@0
|
219 cs{end+1} = '\maketitle';
|
wolffd@0
|
220 %cs{end+1} = '\tableofcontents';
|
wolffd@0
|
221 %cs{end+1} = '\clearpage';
|
wolffd@0
|
222 return;
|
wolffd@0
|
223
|
wolffd@0
|
224 function cs = tex_enddocument
|
wolffd@0
|
225 cs = cell(0);
|
wolffd@0
|
226 cs{end+1} = '\end{document}';
|
wolffd@0
|
227 return;
|
wolffd@0
|
228
|
wolffd@0
|
229 function cs = html_startpage(title)
|
wolffd@0
|
230 % print HTML document headers
|
wolffd@0
|
231 cs = cell(0);
|
wolffd@0
|
232 cs{end+1} = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
|
wolffd@0
|
233 cs{end+1} = '<HTML>';
|
wolffd@0
|
234 cs{end+1} = '<HEAD>';
|
wolffd@0
|
235 cs{end+1} = sprintf(' <TITLE>%s</TITLE>',title);
|
wolffd@0
|
236 cs{end+1} = '</HEAD>';
|
wolffd@0
|
237 cs{end+1} = '<BODY bgcolor=white vlink="#000033" link="#0000ff" text="#000000">';
|
wolffd@0
|
238 if ~isempty(title), cs{end+1} = sprintf('<H1>%s</H1>',title); end
|
wolffd@0
|
239 return;
|
wolffd@0
|
240
|
wolffd@0
|
241 function cs = html_endpage
|
wolffd@0
|
242 % print HTML document footers
|
wolffd@0
|
243 cs = cell(0);
|
wolffd@0
|
244 cs{end+1} = '<P><HR>';
|
wolffd@0
|
245 cs{end+1} = '</BODY>';
|
wolffd@0
|
246 cs{end+1} = '</HTML>';
|
wolffd@0
|
247 return;
|
wolffd@0
|
248
|
wolffd@0
|
249 function files = compiledocument(filename)
|
wolffd@0
|
250 global REPORT_OUTPUT_FMT
|
wolffd@0
|
251 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
252 case 'pdf',
|
wolffd@0
|
253 eval(sprintf('!pdflatex --interaction batchmode %s.tex',filename));
|
wolffd@0
|
254 eval(sprintf('!pdflatex --interaction batchmode %s.tex',filename));
|
wolffd@0
|
255 %eval(sprintf('!acroread %s.pdf &',filename));
|
wolffd@0
|
256 files = {[filename '.aux'],[filename '.log'],[filename '.out'],[filename '.pdf']};
|
wolffd@0
|
257 case 'ps',
|
wolffd@0
|
258 eval(sprintf('!latex --interaction batchmode %s.tex',filename));
|
wolffd@0
|
259 eval(sprintf('!latex --interaction batchmode %s.tex',filename));
|
wolffd@0
|
260 eval(sprintf('!dvips %s.dvi',filename));
|
wolffd@0
|
261 eval(sprintf('!ps2pdf %s.ps',filename));
|
wolffd@0
|
262 %eval(sprintf('!ghostview %s.ps &',filename));
|
wolffd@0
|
263 files = {[filename '.aux'],[filename '.log'],[filename '.out'],[filename '.dvi'],[filename '.pdf']};
|
wolffd@0
|
264 case 'html',
|
wolffd@0
|
265 case 'txt',
|
wolffd@0
|
266 end
|
wolffd@0
|
267 return;
|
wolffd@0
|
268
|
wolffd@0
|
269
|
wolffd@0
|
270 function vstr = defaultformat(val)
|
wolffd@0
|
271 global REPORT_OUTPUT_FMT
|
wolffd@0
|
272 if ischar(val), vstr = val;
|
wolffd@0
|
273 elseif iscellstr(val), vstr = char(val);
|
wolffd@0
|
274 elseif isempty(val), vstr = '';
|
wolffd@0
|
275 elseif isnumeric(val),
|
wolffd@0
|
276 if val==round(val), fmt = '%d'; else fmt = '%.3g'; end
|
wolffd@0
|
277 if abs(val)<=eps, vstr = '0'; else vstr = sprintf(fmt,val); end
|
wolffd@0
|
278 elseif isstruct(val) & isfield(val,'values') & isfield(val,'headers'),
|
wolffd@0
|
279 % a table
|
wolffd@0
|
280 vstr = joinstr(inserttable(val,0),'\n');
|
wolffd@0
|
281 if any(strcmp(REPORT_OUTPUT_FMT,{'ps','pdf'})),
|
wolffd@0
|
282 vstr= inserttominipage(vstr);
|
wolffd@0
|
283 end
|
wolffd@0
|
284 else
|
wolffd@0
|
285 vstr = ''; fprintf(1,'defaultformat unable to handle input\n');
|
wolffd@0
|
286 whos val
|
wolffd@0
|
287 end
|
wolffd@0
|
288 return;
|
wolffd@0
|
289
|
wolffd@0
|
290 %% report elements (list, table, image, link)
|
wolffd@0
|
291
|
wolffd@0
|
292 function str = fmtline(str)
|
wolffd@0
|
293 % replace some formatting elements depeding on output format
|
wolffd@0
|
294 global REPORT_OUTPUT_FMT
|
wolffd@0
|
295 if isempty(str), str = ''; return; end
|
wolffd@0
|
296 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
297 case {'ps','pdf'},
|
wolffd@0
|
298 str = strrep(str,'<B>', '{\bf ');
|
wolffd@0
|
299 str = strrep(str,'<I>', '{\em ');
|
wolffd@0
|
300 str = strrep(str,'<TT>', '{\tt ');
|
wolffd@0
|
301 str = strrep(str,'</B>', '}');
|
wolffd@0
|
302 str = strrep(str,'</I>', '}');
|
wolffd@0
|
303 str = strrep(str,'</TT>','}');
|
wolffd@0
|
304 str = strrep(str,'#','\#');
|
wolffd@0
|
305 str = strrep(str,'%','\%');
|
wolffd@0
|
306 case 'html', % nil
|
wolffd@0
|
307 case 'txt',
|
wolffd@0
|
308 str = strrep(str,'<B>', '*');
|
wolffd@0
|
309 str = strrep(str,'<I>', '*');
|
wolffd@0
|
310 str = strrep(str,'<TT>', '');
|
wolffd@0
|
311 str = strrep(str,'</B>', '*');
|
wolffd@0
|
312 str = strrep(str,'</I>', '*');
|
wolffd@0
|
313 str = strrep(str,'</TT>','');
|
wolffd@0
|
314 end
|
wolffd@0
|
315 return;
|
wolffd@0
|
316
|
wolffd@0
|
317 function cs = insertbreak
|
wolffd@0
|
318 global REPORT_OUTPUT_FMT
|
wolffd@0
|
319 cs = cell(0);
|
wolffd@0
|
320 switch REPORT_OUTPUT_FMT
|
wolffd@0
|
321 case {'ps','pdf'}, cs{end+1} = '';
|
wolffd@0
|
322 case 'html', cs{end+1} = '<P>';
|
wolffd@0
|
323 case 'txt', cs{end+1} = '';
|
wolffd@0
|
324 end
|
wolffd@0
|
325 return;
|
wolffd@0
|
326
|
wolffd@0
|
327 function insertlist(list,enum)
|
wolffd@0
|
328 % make list
|
wolffd@0
|
329 global REPORT_OUTPUT_FMT
|
wolffd@0
|
330 if nargin<2, enum = 0; end
|
wolffd@0
|
331 cs = cell(0);
|
wolffd@0
|
332 switch REPORT_OUTPUT_FMT
|
wolffd@0
|
333 case {'ps','pdf'},
|
wolffd@0
|
334 if enum, tag = 'enumerate'; else tag = 'itemize'; end
|
wolffd@0
|
335 starttag = ['\begin{' tag '}'];
|
wolffd@0
|
336 listtag = '\item ';
|
wolffd@0
|
337 endtag = ['\end{' tag '}'];
|
wolffd@0
|
338 case 'html',
|
wolffd@0
|
339 if enum, tag = 'OL'; else tag = 'UL'; end
|
wolffd@0
|
340 starttag = ['<' tag '>'];
|
wolffd@0
|
341 listtag = '<LI>';
|
wolffd@0
|
342 endtag = ['</' tag '>'];
|
wolffd@0
|
343 case 'txt',
|
wolffd@0
|
344 starttag = '';
|
wolffd@0
|
345 listtag = '- ';
|
wolffd@0
|
346 endtag = '';
|
wolffd@0
|
347 end
|
wolffd@0
|
348 cs{end+1} = starttag;
|
wolffd@0
|
349 for i=1:length(list), cs{end+1} = sprintf('%s %s',listtag,list{i}); end
|
wolffd@0
|
350 cs{end+1} = endtag;
|
wolffd@0
|
351 return;
|
wolffd@0
|
352
|
wolffd@0
|
353 function csout = tablerow(cs,emp,span)
|
wolffd@0
|
354 % construct one table row
|
wolffd@0
|
355 global REPORT_OUTPUT_FMT
|
wolffd@0
|
356 if nargin<2 | isempty(emp), emp = 'none'; end
|
wolffd@0
|
357 if nargin<3 | isempty(span), span = ones(length(cs),2); end
|
wolffd@0
|
358 rowspan = span(:,1); colspan = span(:,2);
|
wolffd@0
|
359 switch emp,
|
wolffd@0
|
360 case 'bold', emp1 = '<B>'; emp2 = '</B>';
|
wolffd@0
|
361 case 'italic', emp1 = '<I>'; emp2 = '</I>';
|
wolffd@0
|
362 case 'fixed', emp1 = '<TT>'; emp2 = '</TT>';
|
wolffd@0
|
363 case 'none', emp1 = ''; emp2 = '';
|
wolffd@0
|
364 case 'header', emp1 = ''; emp2 = ''; tag = 'TH';
|
wolffd@0
|
365 end
|
wolffd@0
|
366 csout = cell(0);
|
wolffd@0
|
367 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
368 case {'pdf','ps'},
|
wolffd@0
|
369 %switch emp,
|
wolffd@0
|
370 % case 'bold', emp1 = '{\bf '; emp2 = '}';
|
wolffd@0
|
371 % case 'italic', emp1 = '{\em '; emp2 = '}';
|
wolffd@0
|
372 % case 'fixed', emp1 = '{\tt '; emp2 = '}';
|
wolffd@0
|
373 % case 'none', emp1 = ''; emp2 = '';
|
wolffd@0
|
374 %end
|
wolffd@0
|
375 s0 = '';
|
wolffd@0
|
376 for i=1:length(cs),
|
wolffd@0
|
377 if rowspan(i) & colspan(i),
|
wolffd@0
|
378 sp1 = ''; sp2 = '';
|
wolffd@0
|
379 if colspan(i)>1, sp1 = [sp1 ' \multicolumn{' num2str(colspan(i)) '}{|c|}{']; sp2 = [sp2 '}']; end
|
wolffd@0
|
380 if rowspan(i)>1, sp1 = [sp1 ' \multirow{' num2str(rowspan(i)) '}{2cm}{']; sp2 = [sp2 '}']; end
|
wolffd@0
|
381 s = s0;
|
wolffd@0
|
382 content = cellstr(defaultformat(cs{i}));
|
wolffd@0
|
383 csout{end+1} = [s sp1 emp1 content{1}];
|
wolffd@0
|
384 for j=2:length(content), csout{end+1} = content{j}; end
|
wolffd@0
|
385 csout{end} = [csout{end} emp2 sp2];
|
wolffd@0
|
386 s0 = ' & ';
|
wolffd@0
|
387 end
|
wolffd@0
|
388 end
|
wolffd@0
|
389 csout{end} = [csout{end} ' \\'];
|
wolffd@0
|
390 case 'html',
|
wolffd@0
|
391 tag = 'TD';
|
wolffd@0
|
392 csout{end+1} = '<TR>';
|
wolffd@0
|
393 for i=1:length(cs),
|
wolffd@0
|
394 if rowspan(i) & colspan(i),
|
wolffd@0
|
395 sp = '';
|
wolffd@0
|
396 if rowspan(i)>1, sp = [sp ' ROWSPAN=' num2str(rowspan(i))]; end
|
wolffd@0
|
397 if colspan(i)>1, sp = [sp ' COLSPAN=' num2str(colspan(i))]; end
|
wolffd@0
|
398 s = sprintf('<%s%s>%s',tag,sp,emp1);
|
wolffd@0
|
399 content = cellstr(defaultformat(cs{i}));
|
wolffd@0
|
400 csout{end+1} = [s content{1}];
|
wolffd@0
|
401 for j=2:length(content), csout{end+1} = content{j}; end
|
wolffd@0
|
402 csout{end} = [csout{end} emp2 '</' tag '>'];
|
wolffd@0
|
403 end
|
wolffd@0
|
404 end
|
wolffd@0
|
405 csout{end+1} = '</TR>';
|
wolffd@0
|
406 case 'txt',
|
wolffd@0
|
407 for i=1:length(cs), csout{end+1} = defaultformat(cs{i}); end
|
wolffd@0
|
408 end
|
wolffd@0
|
409 return;
|
wolffd@0
|
410
|
wolffd@0
|
411 function cs = inserttable(sTable,rowlines,long)
|
wolffd@0
|
412 % put table contents to cellstr
|
wolffd@0
|
413 global REPORT_OUTPUT_FMT
|
wolffd@0
|
414 if nargin<2, rowlines = 1; end
|
wolffd@0
|
415 if nargin<3, long = 0; end
|
wolffd@0
|
416 [rows cols] = size(sTable.values);
|
wolffd@0
|
417 cs = cell(0);
|
wolffd@0
|
418 if isempty(sTable.colfmt), cf = 'c'; sTable.colfmt = cf(ones(1,cols)); end
|
wolffd@0
|
419 if isempty(sTable.span), sTable.span = ones([rows cols 2]); end
|
wolffd@0
|
420 switch REPORT_OUTPUT_FMT
|
wolffd@0
|
421 case {'ps','pdf','tex','latex'}
|
wolffd@0
|
422 li1 = ' \hline';
|
wolffd@0
|
423 if rowlines>0, li2 = li1; li3 = li1;
|
wolffd@0
|
424 elseif rowlines==0, li2 = ''; li3 = li1;
|
wolffd@0
|
425 else li1 = ''; li2 = ''; li3 = '';
|
wolffd@0
|
426 end
|
wolffd@0
|
427 if long, tbl = 'longtable'; else tbl = 'tabular'; end
|
wolffd@0
|
428 cs{end+1} = ['\begin{' tbl '}{' sTable.colfmt '}' li1];
|
wolffd@0
|
429 if ~isempty(sTable.headers),
|
wolffd@0
|
430 row = tablerow(sTable.headers,'bold');
|
wolffd@0
|
431 for i=1:length(row), cs{end+1} = row{i}; end
|
wolffd@0
|
432 cs{end} = [cs{end} li1 li2];
|
wolffd@0
|
433 end
|
wolffd@0
|
434 for i=1:rows,
|
wolffd@0
|
435 row = tablerow(sTable.values(i,:),'',squeeze(sTable.span(i,:,:)));
|
wolffd@0
|
436 for i=1:length(row), cs{end+1} = row{i}; end
|
wolffd@0
|
437 cs{end} = [cs{end} li2];
|
wolffd@0
|
438 end
|
wolffd@0
|
439 if ~rowlines, cs{end} = [cs{end} li3]; end
|
wolffd@0
|
440 cs{end+1} = ['\end{' tbl '}'];
|
wolffd@0
|
441 case 'html'
|
wolffd@0
|
442 cs{end+1} = ['<TABLE BORDER=' num2str(rowlines>0) '>'];
|
wolffd@0
|
443 if ~isempty(sTable.headers),
|
wolffd@0
|
444 row = tablerow(sTable.headers,'header');
|
wolffd@0
|
445 for i=1:length(row), cs{end+1} = row{i}; end
|
wolffd@0
|
446 end
|
wolffd@0
|
447 for i=1:rows,
|
wolffd@0
|
448 row = tablerow(sTable.values(i,:),'',squeeze(sTable.span(i,:,:)));
|
wolffd@0
|
449 for i=1:length(row), cs{end+1} = row{i}; end
|
wolffd@0
|
450 end
|
wolffd@0
|
451 cs{end+1} = '</TABLE>';
|
wolffd@0
|
452 case 'txt'
|
wolffd@0
|
453 cT = [sTable.headers(:)'; sTable.values];
|
wolffd@0
|
454 A = cell2char(cT);
|
wolffd@0
|
455 for i=1:size(A,1), cs{end+1} = A(i,:); end
|
wolffd@0
|
456 end
|
wolffd@0
|
457 return;
|
wolffd@0
|
458
|
wolffd@0
|
459 function A = cell2char(T)
|
wolffd@0
|
460
|
wolffd@0
|
461 [nrow,ncol] = size(T);
|
wolffd@0
|
462 rowsep = 0;
|
wolffd@0
|
463 colsep = 1;
|
wolffd@0
|
464
|
wolffd@0
|
465 % change to strings
|
wolffd@0
|
466 for i=1:nrow,
|
wolffd@0
|
467 for j=1:ncol,
|
wolffd@0
|
468 t = T{i,j};
|
wolffd@0
|
469 if ischar(t), % ok
|
wolffd@0
|
470 elseif isempty(t), T{i,j} = '';
|
wolffd@0
|
471 elseif isstruct(t), % ??
|
wolffd@0
|
472 elseif iscell(t), T{i,j} = cell2char(t);
|
wolffd@0
|
473 elseif isnumeric(t), T{i,j} = num2str(t,3);
|
wolffd@0
|
474 end
|
wolffd@0
|
475 end
|
wolffd@0
|
476 end
|
wolffd@0
|
477
|
wolffd@0
|
478 % widths of columns and heights of rows
|
wolffd@0
|
479 HW = ones(nrow,ncol,2);
|
wolffd@0
|
480 for i=1:nrow, for j=1:ncol, HW(i,j,:) = size(T{i,j}); end, end
|
wolffd@0
|
481 colw = max(HW(:,:,2),[],1);
|
wolffd@0
|
482 rowh = max(HW(:,:,1),[],2);
|
wolffd@0
|
483
|
wolffd@0
|
484 % the table itself
|
wolffd@0
|
485 A = char(32*ones(sum(rowh)+rowsep*(nrow-1),sum(colw)+colsep*(ncol-1)));
|
wolffd@0
|
486 for i=1:nrow,
|
wolffd@0
|
487 for j=1:ncol,
|
wolffd@0
|
488 i0 = (i-1)*rowsep+sum(rowh(1:i-1));
|
wolffd@0
|
489 j0 = (j-1)*colsep+sum(colw(1:j-1));
|
wolffd@0
|
490 S = char(32*ones(rowh(i),colw(j)));
|
wolffd@0
|
491 si = size(T{i,j}); S(1:si(1),1:si(2)) = T{i,j};
|
wolffd@0
|
492 A(i0+[1:rowh(i)],j0+[1:colw(j)]) = S;
|
wolffd@0
|
493 end
|
wolffd@0
|
494 end
|
wolffd@0
|
495 return;
|
wolffd@0
|
496
|
wolffd@0
|
497
|
wolffd@0
|
498 function s = inserttominipage(s,width)
|
wolffd@0
|
499 if nargin<2 | isempty(width) | isnan(width), width = 1; end
|
wolffd@0
|
500 width = ['{' num2str(width) '\columnwidth}'];
|
wolffd@0
|
501 mp1 = '\begin{minipage}[t]'; mp2 = '\end{minipage}';
|
wolffd@0
|
502 if size(s,1)==1, s = [mp1 width s mp2];
|
wolffd@0
|
503 else s = char({[mp1 width]; s; mp2});
|
wolffd@0
|
504 end
|
wolffd@0
|
505 return;
|
wolffd@0
|
506
|
wolffd@0
|
507 function cs = insertfigure(fname,boxsize,inminipage)
|
wolffd@0
|
508 global REPORT_OUTPUT_FMT
|
wolffd@0
|
509 if nargin<2, boxsize = [NaN 1]; end
|
wolffd@0
|
510 if nargin<3, inminipage = 0; end
|
wolffd@0
|
511 htmlpagewidth = 800;
|
wolffd@0
|
512 si = cell(0);
|
wolffd@0
|
513 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
514 case {'ps','pdf'},
|
wolffd@0
|
515 if ~isnan(boxsize(1)), si{end+1} = ['height=' num2str(boxsize(1)) '\textheight']; end
|
wolffd@0
|
516 if ~isnan(boxsize(2)), si{end+1} = ['width=' num2str(boxsize(2)) '\columnwidth']; end
|
wolffd@0
|
517 if length(si), si = [', ' joinstr(si, ', ', ', ')]; end
|
wolffd@0
|
518 case 'html',
|
wolffd@0
|
519 if ~isnan(boxsize(1)), si{end+1} = ['HEIGHT=' num2str(htmlpagewidth*boxsize(1))]; end
|
wolffd@0
|
520 if ~isnan(boxsize(2)), si{end+1} = ['WIDTH=' num2str(htmlpagewidth*boxsize(2))]; end
|
wolffd@0
|
521 if length(si), si = [' ' joinstr(si, ' ', ' ')]; end
|
wolffd@0
|
522 case 'txt',
|
wolffd@0
|
523 % nil
|
wolffd@0
|
524 end
|
wolffd@0
|
525 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
526 case 'ps', s = ['\epsfig{file=./' fname '.ps ' si '}'];
|
wolffd@0
|
527 case 'pdf', s = ['\includegraphics[' si ']{./' fname '.pdf}'];
|
wolffd@0
|
528 case 'html',
|
wolffd@0
|
529 fn = [fname '.' fmt2imgfmt];
|
wolffd@0
|
530 s = ['<IMG SRC="' fn '" ALIGN="center" ALT="' fname '"' si '>'];
|
wolffd@0
|
531 s = makelinkfrom(fn,s);
|
wolffd@0
|
532 case 'txt',
|
wolffd@0
|
533 s = ['[image:' fname ']'];
|
wolffd@0
|
534 end
|
wolffd@0
|
535 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
536 case {'ps','pdf'},
|
wolffd@0
|
537 if inminipage, s = inserttominipage(s,boxsize(2)); end
|
wolffd@0
|
538 case 'html',
|
wolffd@0
|
539 s = ['<CENTER>' s '</CENTER>'];
|
wolffd@0
|
540 case 'txt',
|
wolffd@0
|
541 % nil
|
wolffd@0
|
542 end
|
wolffd@0
|
543 cs = {s};
|
wolffd@0
|
544 return;
|
wolffd@0
|
545
|
wolffd@0
|
546 function str = makelinkfrom(linkto,anchor)
|
wolffd@0
|
547 global REPORT_OUTPUT_FMT
|
wolffd@0
|
548 if iscell(linkto),
|
wolffd@0
|
549 if strcmp(REPORT_OUTPUT_FMT,'html'), linkto = joinstr(linkto,'','#');
|
wolffd@0
|
550 else linkto = joinstr(linkto,'','');
|
wolffd@0
|
551 end
|
wolffd@0
|
552 end
|
wolffd@0
|
553 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
554 case 'pdf', str = ['\hyperlink{' linkto '}{' anchor '}'];
|
wolffd@0
|
555 case 'ps', str = [anchor ' (p.\pageref{' linkto '})'];
|
wolffd@0
|
556 case 'html', str = ['<a href="' linkto '">' anchor '</a>'];
|
wolffd@0
|
557 case 'txt', str = '';
|
wolffd@0
|
558 end
|
wolffd@0
|
559 return;
|
wolffd@0
|
560
|
wolffd@0
|
561 function str = makelinkto(linkname)
|
wolffd@0
|
562 global REPORT_OUTPUT_FMT
|
wolffd@0
|
563 switch REPORT_OUTPUT_FMT,
|
wolffd@0
|
564 case 'pdf',
|
wolffd@0
|
565 fmt = '\pdfdest name {%s} fit \pdfoutline goto name {%s} {%s}';
|
wolffd@0
|
566 str = sprintf(fmt,linkname,linkname,linkname);
|
wolffd@0
|
567 case 'ps', str = ['\label{' linkname '}'];
|
wolffd@0
|
568 case 'html', str = ['<a name="' linkname '"> </a>'];
|
wolffd@0
|
569 case 'txt', str = '';
|
wolffd@0
|
570 end
|
wolffd@0
|
571 return;
|
wolffd@0
|
572
|