comparison m-toolbox/classes/@ltpda_uoh/report.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % REPORT generates an HTML report about the input objects.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: REPORT generates an HTML report about the input objects.
5 %
6 % CALL: report(objs);
7 % report(objs, options);
8 %
9 % INPUTS: objs - LTPDA objects
10 % options - a plist of options
11 %
12 % PARAMETERS:
13 % 'dir' - report dir [default: <temp dir>/ltpda_report/<date><time>]
14 % 'extras' - true [default] or false: plot data and diagrams
15 % for objects, output mfile, and type() output.
16 % 'desc' - give a description to appear on the main report
17 % page.
18 % 'save' - include saved versions of the objects in the
19 % report directory. Objects are saved as XML.
20 % Specify with true or false [default]
21 % 'zip' - compress the report directory to a ZIP file
22 % 'plots' - specify a cell-array of objects to build
23 % plots on the main page. Each cell gets its
24 % own plot. Example: {[a1, a3], {a5}}.
25 % 'overwrite' - overwrite the report directory if it exists.
26 % Specify true or false [default].
27 %
28 % <a href="matlab:utils.helper.displayMethodInfo('ltpda_uoh', 'report')">Parameters Description</a>
29 %
30 % VERSION: $Id: report.m,v 1.20 2011/04/08 08:56:30 hewitson Exp $
31 %
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 function varargout = report(varargin)
34
35 % starting initial checks
36 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
37
38 % Check if this is a call for parameters
39 if utils.helper.isinfocall(varargin{:})
40 varargout{1} = getInfo(varargin{3});
41 return
42 end
43
44 % Collect input variable names
45 in_names = cell(size(varargin));
46 for ii = 1:nargin,in_names{ii} = inputname(ii);end
47
48 % Collect all objs and plists
49 objs = {};
50 objnames = {};
51 classes = utils.helper.ltpda_userclasses;
52 for jj=1:numel(classes)
53 try
54 % can I create this type of class?
55 feval(classes{jj});
56 [oos, obj_invars] = utils.helper.collect_objects(varargin(:), classes{jj}, in_names);
57 if ~isempty(oos) && ~isa(oos, 'plist')
58 objs = [objs {oos}];
59 objnames = [objnames obj_invars];
60 end
61 end
62 end
63 % get plist
64 pl = utils.helper.collect_objects(varargin(:), 'plist');
65 pl = combine(pl, getDefaultPlist('Default'));
66
67 % Get options
68 outdir = find(pl, 'dir');
69 plotOn = find(pl, 'extras');
70 saveXML = find(pl, 'save');
71 compress = find(pl, 'zip');
72 groupPlot = find(pl, 'plots');
73
74 % Create output dir
75 if isempty(outdir)
76 outdir = fullfile(tempdir, 'ltpda_report', datestr(now, 30));
77 elseif (outdir == '.')
78 outdir = fullfile('ltpda_report', datestr(now, 30));
79 end
80
81 % Does the directory exist?
82 if find(pl, 'overwrite')
83 if exist(outdir, 'dir') ~= 0
84 [success, msg, msgid] = rmdir(outdir, 's');
85 if ~success, disp(msg), return, end
86 end
87 else % check with the user
88 if exist(outdir, 'dir') == 7
89 disp('The requested report directory already exists.')
90 r = input('Do you want to overwrite it? [y/n] ', 's');
91 if strcmpi(r, 'y')
92 [success, msg, msgid] = rmdir(outdir, 's');
93 if ~success, disp(msg), return, end
94 else
95 return
96 end
97 end
98 end
99 mkdir(outdir);
100 mkdir(fullfile(outdir, 'images'));
101
102 % Write .html file
103 indexFile = fullfile(outdir, 'index.html');
104 fd = fopen(indexFile, 'w+');
105
106 header = getHeader();
107 footer = getFooter();
108
109 % write header
110 fprintf(fd, header);
111
112 % write description
113 desc = find(pl, 'desc');
114 if ~iscell(desc), desc = {desc}; end
115 for kk=1:numel(desc)
116 fprintf(fd, '<p>%s</p>\n', desc{kk});
117 end
118
119 % write index entry
120 fprintf(fd, '<br><h2><a name="toc">Table of Contents</a></h2>\n');
121 [s, htmlfiles] = writeTableOfContents(objs, objnames);
122 fprintf(fd, s);
123
124 % Group plot?
125 if ~isempty(groupPlot)
126 % go through each cell - one plot per cell
127 for kk=1:numel(groupPlot)
128 % get objects
129 group = groupPlot{kk};
130 fprintf(fd, '<hr>\n');
131 fprintf(fd, '<h2>Plot %d</h2>', kk);
132 if isa(group, 'ao')
133 imname = 'images/groupplot_001.png';
134 n = 1;
135 while exist(fullfile(outdir, imname),'file')
136 n = n + 1;
137 imname = sprintf('images/groupplot_%03d.png', n);
138 end
139 % make a plot
140 hfig = iplot(group);
141 % make image
142 saveas(hfig, fullfile(outdir, imname));
143 % make link
144 fprintf(fd, '<img src="%s" alt="Plot" width="800px" border="3">\n', imname);
145 close(hfig);
146 else
147
148 end
149 end
150 end
151
152 % write individual html files
153 writeObjFiles(fd, objs, htmlfiles, header, footer, outdir, plotOn, saveXML);
154
155 % reportee info
156 fprintf(fd, '<hr>\n');
157 fprintf(fd, '<br><h2>report created by:</h2>\n');
158 s = obj2table(provenance, outdir);
159 fprintf(fd, s);
160
161 fprintf(fd, '\n');
162 fprintf(fd, '\n');
163 % write footer
164 fprintf(fd, footer);
165 % Close
166 fclose(fd);
167
168 % copy stylesheet
169 dp = which('docstyle.css');
170 copyfile(dp, outdir);
171 copyfile(dp, fullfile(outdir, 'html'));
172
173 % zip ?
174 if compress
175 zip([outdir '.zip'], outdir);
176 end
177
178 % open report
179 if isempty(pl.find('dir'))
180 web(fullfile('file:///', outdir, 'index.html'))
181 else
182 web(fullfile('file:///', pwd, outdir, 'index.html'))
183 end
184
185 utils.helper.msg(utils.const.msg.PROC1, 'report written to %s', outdir);
186 if nargout == 1
187 varargout{1} = outdir;
188 end
189
190 end
191
192 %--------------------------------------------------------------------------
193 % Write provenance info
194 %
195 function s = obj2table(obj, reportDir)
196
197 % prepare table
198 s = sprintf('<p>\n\t');
199 s = [s sprintf(' <table border="1" cellspacing="0" cellpadding="0" width="1%%%%">\n')];
200 s = [s sprintf(' <tr valign="top">\n')];
201 s = [s sprintf(' <td align="center" valign="top">\n')];
202 s = [s sprintf(' <table border="0" cellspacing="0" cellpadding="3" width="100%%%%">\n')];
203 s = [s sprintf(' <colgroup>\n')];
204 s = [s sprintf(' <col width="1%%%%">\n')];
205 s = [s sprintf(' <col width="1%%%%">\n')];
206 s = [s sprintf(' </colgroup>\n')];
207 s = [s sprintf(' <thead>\n')];
208 s = [s sprintf(' <tr valign="top" bgcolor="#000000">\n')];
209 s = [s sprintf(' <td align="center" colspan="2"><font color="#FFFFFF">%s</font></td></tr>\n', upper(class(obj)))];
210 s = [s sprintf(' <tr bgcolor="#B2B2B2"valign="top">\n')];
211 s = [s sprintf(' <th>Property</th>\n')];
212 s = [s sprintf(' <th>Value</th>\n')];
213 s = [s sprintf(' </tr>\n')];
214 s = [s sprintf(' </thead>\n')];
215 s = [s sprintf(' <tbody>\n')];
216 props = properties(obj);
217 cols = {'#E9E9E9', '#FFFFFF'};
218 for jj=1:numel(props)
219 prop = props{jj};
220 val = obj.(prop);
221 s = [s sprintf(' <tr valign="top" bgcolor="%s">\n', cols{mod(jj,2)+1})];
222 s = [s sprintf(' <td><h4><font color="#890022"><i>%s</i></font></h4></td>\n', props{jj})];
223 %---- EXCEPTIONS -------%
224 if isempty(val)
225 valstr = '<font color="#0003B6"><i>empty</i></font>';
226 else
227 if strcmp(prop, 'mfile')
228 valstr = '<i>see above</i>';
229 elseif strcmp(prop, 'mdlfile')
230 valstr = '<i>SIMULINK model file</i>';
231 else
232 valstr = val2html(val, reportDir);
233 end
234 end
235 s = [s sprintf(' <td>%s</td>\n', valstr)];
236 s = [s sprintf(' </tr>\n')];
237 end
238 s = [s sprintf(' </tbody>\n')];
239 s = [s sprintf(' </table>\n')];
240 s = [s sprintf(' </td>\n')];
241 s = [s sprintf(' </tr>\n')];
242 s = [s sprintf(' </table>\n')];
243 s = [s sprintf('</p>\n')];
244 end
245
246
247 %--------------------------------------------------------------------------
248 % Convert a MATLAB type to an html string
249 %
250 function s = val2html(val, reportDir)
251 MAX_STR_LENGTH = 50;
252 MAX_NUM_LENGTH = 10;
253 if ischar(val) % String
254 s = ['<font color="#49B64B">' strtrunc(val, MAX_STR_LENGTH) '</font>'];
255 elseif iscell(val) % Symbol
256 cs = size(val);
257 if numel(val) == 1
258 s = val2html(val{1});
259 else
260 s = '<table border="1" cellpadding="2" cellspacing="0">\n';
261 s = [s sprintf(' <thead>\n')];
262 s = [s sprintf(' <tr valign="top">\n')];
263 s = [s sprintf('<th bgcolor="#8BCEC3"></th>')];
264 for jj=1:cs(2) % loop over columns
265 s = [s sprintf('<th bgcolor="#8BCEC3">%d</th>', jj)];
266 end
267 s = [s sprintf(' </tr>\n')];
268 s = [s sprintf(' </thead>\n')];
269 for jj=1:cs(1)
270 s = [s '<tr>\n'];
271 s = [s sprintf('<th bgcolor="#8BCEC3">%d</th>', jj)];
272 for kk=1:cs(2)
273 s = [s '<td align="center" valign="middle" >\n'];
274 s = [s val2html(val{jj,kk})];
275 s = [s '</td>\n'];
276 end
277 s = [s '</tr>\n'];
278 end
279 s = [s '</table>\n'];
280 end
281 %%%%%%%% SYMBOLS
282 elseif isa(val, 'sym')
283
284 if numel(val) == 1
285 s = strtrunc(char(sym), 50);
286 else
287 cs = size(val);
288 s = '<table border="1" width="600px" cellpadding="3" cellspacing="0">\n';
289 s = [s sprintf(' <thead>\n')];
290 s = [s sprintf(' <tr valign="top">\n')];
291 s = [s sprintf('<th bgcolor="#B2B2B2"></th>')];
292 for jj=1:cs(2) % loop over columns
293 s = [s sprintf('<th bgcolor="#B2B2B2">%d</th>', jj)];
294 end
295 s = [s sprintf(' </tr>\n')];
296 s = [s sprintf(' </thead>\n')];
297
298 for jj=1:cs(1) % loop over rows
299 s = [s '<tr>\n'];
300 s = [s sprintf('<th bgcolor="#B2B2B2">%d</th>', jj)];
301 for kk=1:cs(2) % loop over columns
302 s = [s '<td align="center" valign="middle" >\n'];
303 s = [s '<font color="#6969B6">' strtrunc(char(val(jj,kk)),50) '</font>'];
304 s = [s '</td>\n'];
305 end
306 s = [s '</tr>\n'];
307 end
308 s = [s '</table>\n'];
309 end
310 elseif isa(val, 'ltpda_obj') % LTPDA object
311 if isa(val, 'history')
312 % make image
313 imname = 'images/hist_img_001.png';
314 n = 1;
315 while exist(fullfile(reportDir, imname),'file')
316 n = n + 1;
317 imname = sprintf('images/hist_img_%03d.png', n);
318 end
319 % make image
320 dotview(val, plist('filename', fullfile(reportDir, imname), 'view', false, 'format', 'png'));
321 % make link
322 s = sprintf('<img src="%s" alt="History Plot" border="3">\n', imname);
323 elseif isa(val, 'unit') || isa(val, 'time') || isa(val, 'plist')
324 s = mask_special_char(char(val));
325 else
326 s = obj2table(val, reportDir);
327 end
328 elseif islogical(val)
329 if val
330 s = '<i>true</i>';
331 else
332 s = '<i>false</i>';
333 end
334 elseif isnumeric(val) % Numbers
335 if isempty(val)
336 s = '<font color="#0003B6"><i>empty</i></font>';
337 else
338 if numel(val) > 1
339 s = [sprintf('<font color="#0003B6"><tt><font color="#000000">[%dx%d]</font>', size(val,1), size(val,2)) mat2str(val(1:min(numel(val), MAX_NUM_LENGTH)), 4)];
340 else
341 s = ['<font color="#0003B6"><tt>' mat2str(val(1:min(numel(val), MAX_NUM_LENGTH)), 4)];
342 end
343 if numel(val) > MAX_NUM_LENGTH
344 s = [s '...'];
345 end
346 s = [s '</tt></font>'];
347 end
348 else
349 s = strtrunc(char(val), MAX_STR_LENGTH);
350 end
351
352 end
353
354
355 function txt = Cell2String(c)
356 % recursive code to print the content of cell arrays
357 if iscell(c) % for a cell
358 txt = '';%;
359 for i=1:size(c,1)
360 if i==1
361 txti = '{';
362 else
363 txti = ' ';
364 end
365 for j=1:size(c,2)
366 txti = [txti ' ' Cell2String(c{i,j})];
367 end
368 if i==size(c,1)
369 txti = [txti, ' }'];
370 end
371 txt = strvcat(txt, txti);
372 end
373 elseif isa(c, 'sym')
374 txt = char(c);
375 elseif islogical(c) % for a logical
376 txt = mat2str(c);
377 elseif isnumeric(c)||isa(c,'sym') % for a numerical array, only size is displayed
378 if size(c,1)+size(c,2)==0 % for 0x0 array
379 txt = ' [] ';
380 elseif isa(c,'double') && (norm(c)==0) % for zero array (test dos not carsh for sym)
381 txt = ' [] ';
382 else % for non empty array
383 if size(c,1)>9
384 txt1 = ['[',num2str(size(c,1))];
385 else
386 txt1 = [' [',num2str(size(c,1))];
387 end
388 if size(c,2)>9
389 txt2 = [num2str(size(c,2)),']'];
390 else
391 txt2 = [num2str(size(c,2)),'] '];
392 end
393 txt = [txt1,'x',txt2 ];
394 end
395 % txt = mat2str(c); % old display
396 elseif ischar(c)
397 txt = ['''' c ''''];
398 else
399 txt = char(c);
400 end
401 end
402
403 %--------------------------------------------------------------------------
404 % Truncate a string
405 %
406 function s = strtrunc(s, n)
407 sl = length(s);
408 s = s(1:min(sl, n));
409 if sl > n
410 s = [s '...'];
411 end
412 s = mask_special_char(s);
413 end
414
415 %--------------------------------------------------------------------------
416 % Mask the special characters '<', '>' and &
417 %
418 % '<' with '&lt;'
419 % '>' with '&gt;'
420 % '&' with '&amp;'
421 %
422 function s = mask_special_char(s)
423 s = strrep(s, '&' ,'&amp;');
424 s = strrep(s, '<', '&lt;');
425 s = strrep(s, '>' ,'&gt;');
426 end
427
428 %--------------------------------------------------------------------------
429 % Write a table of contents for the input objects
430 %
431 function [s, filenames] = writeTableOfContents(objs, objnames)
432
433 filenames = {};
434
435 % start table
436 s = sprintf('<p>\n\t');
437 s = [s sprintf(' <table border="1" cellspacing="0" cellpadding="0" width="20%%%%">\n')];
438 s = [s sprintf(' <tr valign="top">\n')];
439 s = [s sprintf(' <td valign="top">\n')];
440 s = [s sprintf(' <table border="0" cellspacing="0" cellpadding="1" width="100%%%%">\n')];
441 s = [s sprintf(' <colgroup>\n')];
442 s = [s sprintf(' <col width="1%%%%">\n')];
443 s = [s sprintf(' <col width="1%%%%">\n')];
444 s = [s sprintf(' </colgroup>\n')];
445 s = [s sprintf(' <thead>\n')];
446 s = [s sprintf(' <tr valign="top">\n')];
447 s = [s sprintf(' <th bgcolor="#B2B2B2">obj #</th>\n')];
448 s = [s sprintf(' <th bgcolor="#B2B2B2">link</th>\n')];
449 s = [s sprintf(' </tr>\n')];
450 s = [s sprintf(' </thead>\n')];
451 s = [s sprintf(' <tbody>\n')];
452
453 cols = {'#E9E9E9', '#FFFFFF'};
454 nn = 1;
455 for jj=1:numel(objs)
456 for kk=1:numel(objs{jj})
457 obj = objs{jj}(kk);
458 % make filename
459 filenames{nn} = sprintf('obj_%03d', nn);
460 % write table entry
461 s = [s sprintf(' <tr valign="top" bgcolor="%s">\n', cols{mod(nn,2)+1})];
462 s = [s sprintf(' <td><font color="#890022">%03d</font></td>\n', nn)];
463 s = [s sprintf(' <td><a href="index.html#%s">%s [%s]</a></td>\n', filenames{nn}, strtrunc(objnames{nn}, 30), class(obj))];
464 s = [s sprintf(' </tr>\n')];
465 nn = nn + 1;
466 end
467 end
468 s = [s sprintf(' </tr>\n')];
469 s = [s sprintf(' </tbody>\n')];
470 s = [s sprintf(' </table>\n')];
471 s = [s sprintf(' </td>\n')];
472 s = [s sprintf(' </tr>\n')];
473 s = [s sprintf(' </table>\n')];
474 s = [s sprintf('</p>\n')];
475 end
476
477
478 function s = getFooter()
479 s = '</body>\n</html>\n';
480 end
481
482 function s = getHeader()
483 s = '';
484
485 % write HTML header
486 s = [s sprintf('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n')];
487 s = [s sprintf('"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">\n')];
488 s = [s sprintf('<html lang="en">\n')];
489 s = [s sprintf('<head>\n')];
490 s = [s sprintf('<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">\n')];
491 s = [s sprintf('\n')];
492 s = [s sprintf('\n')];
493
494 % Page Title
495 pageTitle = ['LTPDA Report from ' datestr(now)];
496 s = [s sprintf('<title>%s</title>\n', pageTitle)];
497 s = [s sprintf('<link rel="stylesheet" href="docstyle.css" type="text/css">\n')];
498 s = [s sprintf('<meta name="generator" content="DocBook XSL Stylesheets V1.52.2">\n')];
499 s = [s sprintf('<meta name="description" content="Presents details of an LTPDA object.">\n')];
500 s = [s sprintf('</head>\n')];
501 s = [s sprintf('\n')];
502 s = [s sprintf('\n')];
503 s = [s sprintf('<body>\n')];
504 s = [s sprintf('<a name="top"><table cellpadding="5" cellspacing="0" width="100%%%%" bgcolor="#F9E767"><tr><td>\n')];
505 s = [s sprintf(' <h1 class="title">%s</h1></td></tr></table>\n\n', pageTitle)];
506 s = [s sprintf('<hr><br></a>\n\n')];
507
508 end
509
510 %--------------------------------------------------------------------------
511 % Write html file for each object
512 %
513 function writeObjFiles(fd, objs, filenames, header, footer, outdir, plotOn, saveXML)
514
515 % Loop over objects
516 nn = 1;
517 for jj=1:numel(objs)
518 for kk=1:numel(objs{jj})
519 % get object
520 obj = objs{jj}(kk);
521
522 % Object name
523 fprintf(fd, '<table width="100%%%%" bgcolor="#F9F19B" cellpadding="5" cellspacing="0"><tr><td>\n');
524 fprintf(fd, '<h1><a name="%s">Name: %s</a></h1>\n', filenames{nn}, mask_special_char(obj.name));
525 fprintf(fd, '</td></tr></table>\n');
526 fprintf(fd, '<p><h3><a href="index.html#top">Back to Top</a></h3></p>\n');
527 fprintf(fd, '<hr>\n');
528 fprintf(fd, '<h2>Class: %s</h2>\n', class(obj));
529
530 % Description
531 if isprop(obj, 'description')
532 fprintf(fd, '<hr>\n');
533 fprintf(fd, '<h2>Description</h2>\n');
534 if isempty(obj.description)
535 fprintf(fd, '<i>none</i>\n');
536 else
537 fprintf(fd, '<p>%s</p>\n', mask_special_char(obj.description));
538 end
539 end
540
541 % Additional stuff
542 if plotOn
543 if isa(obj, 'ao')
544 writeAOextras(obj, fd, outdir);
545 elseif isa(obj, 'miir')
546 writeMIIRextras(obj, fd, outdir);
547 elseif isa(obj, 'mfir')
548 writeMFIRextras(obj, fd, outdir);
549 elseif isa(obj, 'pzmodel')
550 writePZMODELextras(obj, fd, outdir);
551 elseif isa(obj, 'ssm')
552 writeSSMextras(obj, fd, outdir)
553 else
554 % no extras for this type
555 end
556 end
557
558 % write object table
559 fprintf(fd, '<hr>\n');
560 fprintf(fd, '<h2>Object Table View</h2>\n');
561 s = obj2table(obj, outdir);
562 fprintf(fd, s);
563
564 fprintf(fd, '<p><h3><a href="index.html#top">Back to Top</a></h3></p>\n');
565
566 % save XML ?
567 if saveXML
568 [path, name, ext] = fileparts(filenames{nn});
569 xmldir = fullfile(outdir, 'xml');
570 mkdir(xmldir);
571 xmlfile = fullfile(xmldir, [name '.xml']);
572 save(obj, xmlfile);
573 end
574 nn = nn + 1;
575 end % End loop over objects
576 end % Loop over object types
577 end
578
579 %--------------------------------------------------------------------------
580 % Write extra bits for SSM
581 %
582 function writeSSMextras(obj, fd, outdir)
583
584 %-----------------------------------------------
585 % make dot view
586 % make image
587 fprintf(fd, '<hr>\n');
588 fprintf(fd, '<h2>Block Diagram</h2>\n');
589 imname = 'images/ssm_img_001.png';
590 n = 1;
591 while exist(fullfile(outdir, imname),'file')
592 n = n + 1;
593 imname = sprintf('images/ssm_img_%03d.png', n);
594 end
595 % make image
596 dotview(obj, plist('filename', fullfile(outdir, imname), 'view', false, 'format', 'png'));
597 % make link
598 fprintf(fd, '<p><img src="%s" alt="SSM Diagram" border="3"></p>\n', imname);
599
600 end
601 %--------------------------------------------------------------------------
602 % Write extra bits for MIIR
603 %
604 function writeMIIRextras(obj, fd, outdir)
605
606 %-----------------------------------------------
607 % plot response
608 % make image
609 fprintf(fd, '<hr>\n');
610 fprintf(fd, '<h2>Response</h2>\n');
611 imname = 'images/resp_img_001.png';
612 n = 1;
613 while exist(fullfile(outdir, imname),'file')
614 n = n + 1;
615 imname = sprintf('images/resp_img_%03d.png', n);
616 end
617 % make a plot
618 r = resp(obj);
619 hfig = iplot(r);
620 % make image
621 if ~isempty(hfig)
622 saveas(hfig, fullfile(outdir, imname));
623 % make link
624 fprintf(fd, '<p><img src="%s" alt="MIIR Response" width="800px" border="3"></p>\n', imname);
625 close(hfig);
626 else
627 fprintf(fd, '<p><font color="#0003B6"><i>empty</i></font></p>\n');
628 end
629
630 end
631 %--------------------------------------------------------------------------
632 % Write extra bits for MFIR
633 %
634 function writeMFIRextras(obj, fd, outdir)
635
636 %-----------------------------------------------
637 % plot response
638 % make image
639 fprintf(fd, '<hr>\n');
640 fprintf(fd, '<h2>Response</h2>\n');
641 imname = 'images/resp_img_001.png';
642 n = 1;
643 while exist(fullfile(outdir, imname),'file')
644 n = n + 1;
645 imname = sprintf('images/resp_img_%03d.png', n);
646 end
647 % make a plot
648 hfig = iplot(resp(obj));
649 % make image
650 if ~isempty(hfig)
651 saveas(hfig, fullfile(outdir, imname));
652 % make link
653 fprintf(fd, '<p><img src="%s" alt="MFIR Response" width="800px" border="3"></p>\n', imname);
654 close(hfig);
655 else
656 fprintf(fd, '<p><font color="#0003B6"><i>empty</i></font></p>\n');
657 end
658
659 end
660 %--------------------------------------------------------------------------
661 % Write extra bits for pzmodels
662 %
663 function writePZMODELextras(obj, fd, outdir)
664
665 %-----------------------------------------------
666 % plot response
667 % make image
668 fprintf(fd, '<hr>\n');
669 fprintf(fd, '<h2>Response</h2>\n');
670 imname = 'images/resp_img_001.png';
671 n = 1;
672 while exist(fullfile(outdir, imname),'file')
673 n = n + 1;
674 imname = sprintf('images/resp_img_%03d.png', n);
675 end
676 % make a plot
677 hfig = iplot(resp(obj));
678 % make image
679 if ~isempty(hfig)
680 saveas(hfig, fullfile(outdir, imname));
681 % make link
682 fprintf(fd, '<p><img src="%s" alt="PZMODEL Response" width="800px" border="3"></p>\n', imname);
683 close(hfig);
684 else
685 fprintf(fd, '<p><font color="#0003B6"><i>empty</i></font></p>\n');
686 end
687 end
688 %--------------------------------------------------------------------------
689 % Write extra bits for AOs
690 %
691 function writeAOextras(obj, fd, outdir)
692
693 %-------------------------------------------
694 % PLOT
695 fprintf(fd, '<hr>\n');
696 fprintf(fd, '<h2>Plot</h2>\n');
697 imname = 'images/ao_img_001.png';
698 n = 1;
699 while exist(fullfile(outdir, imname),'file')
700 n = n + 1;
701 imname = sprintf('images/ao_img_%03d.png', n);
702 end
703 % make a plot
704 hfig = iplot(obj);
705 % make image
706 if ~isempty(hfig)
707 saveas(hfig, fullfile(outdir, imname));
708 % make link
709 fprintf(fd, '<p><img src="%s" alt="AO Plot" width="800px" border="3"></p>\n', imname);
710 close(hfig);
711 else
712 fprintf(fd, '<p><font color="#0003B6"><i>empty</i></font></p>\n');
713 end
714
715 %-------------------------
716 % Output of type
717 if ~isempty(obj.hist)
718 cmds = hist2m(obj.hist, plist('stop_option', 'full'));
719 txt = mfile2html(cmds(end:-1:1));
720 else
721 txt = '<p><font color="#0003B6"><i>empty</i></font></p>';
722 end
723 fprintf(fd, '<hr>\n');
724 fprintf(fd, '<h2>History dump</h2>\n');
725 fprintf(fd, '<br><p>This is the output of <tt>type(<i>object</i>)</tt></p>\n');
726 fprintf(fd, '<p><div class="fragment"><pre>\n');
727 fprintf(fd, '\n%s', txt);
728 fprintf(fd, '</pre></div></p>\n');
729
730 end
731
732 %--------------------------------------------------------------------------
733 % Reformat an mfile contained in a cell array to be output as html
734 function txt = mfile2html(mfile)
735 % add format tags
736 for kk=1:numel(mfile)
737 % make strings
738
739 % Mask '&' in the strings
740 mfile{kk} = regexprep(mfile{kk}, '(''[^'']*'')', '${strrep($1, ''&'', ''&amp;'')}');
741 % Mask '>' in the strings
742 mfile{kk} = regexprep(mfile{kk}, '(''[^'']*'')', '${strrep($1, ''>'', ''&gt;'')}');
743 % Mask '<' in the strings
744 mfile{kk} = regexprep(mfile{kk}, '(''[^'']*'')', '${strrep($1, ''<'', ''&lt;'')}');
745 mfile{kk} = regexprep(mfile{kk}, '''([^''\\]*(\\.[^''\\]*)*)''', '<span class="string">''$1''</span>');
746 % make comments
747 idx = strfind(mfile{kk}, '%');
748 if ~isempty(idx)
749 mfile{kk} = [mfile{kk}(1:idx(1)-1) '<span class="comment">' mfile{kk}(idx(1):end) '</span>'];
750 end
751 end
752 % reformat into a big string
753 txt = sprintf([repmat('%s\t',1,size(mfile,1)),'\n'],mfile{:});
754 txt = strrep(txt, '`', '''');
755 end
756
757 %--------------------------------------------------------------------------
758 % Get Info
759 %
760 function ii = getInfo(varargin)
761 if nargin == 1 && strcmpi(varargin{1}, 'None')
762 sets = {};
763 pls = [];
764 elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
765 sets{1} = varargin{1};
766 pls = getDefaultPlist(sets{1});
767 else
768 sets = {'Default'};
769 pls = [];
770 for kk=1:numel(sets)
771 pls = [pls getDefaultPlist(sets{kk})];
772 end
773 end
774 % Build info object
775 ii = minfo(mfilename, 'ltpda_uoh', 'ltpda', utils.const.categories.output, '$Id: ', sets, pls);
776 ii.setModifier(false);
777 ii.setOutmin(0);
778 end
779
780 function plout = getDefaultPlist(set)
781 persistent pl;
782 persistent lastset;
783 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set)
784 pl = buildplist(set);
785 lastset = set;
786 end
787 plout = pl;
788 end
789
790 function plo = buildplist(set)
791 switch lower(set)
792 case 'default'
793 plo = plist('dir', '', 'extras', true, 'desc', '', ...
794 'save', false, 'zip', false, 'plots', {}, ...
795 'overwrite', false);
796 otherwise
797 error('### Unknown parameter set [%s].', set);
798 end
799 end
800