comparison m-toolbox/classes/@LTPDAworkbench/export.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 % EXPORT the current pipeline as commands to an m-file or to the terminal.
2 %
3 % CALL: wb.export % export to terminal
4 % wb.export('foo.m') % export to file
5 %
6 % M Hewitson 17-11-08
7 %
8 % $Id: export.m,v 1.3 2010/09/17 14:09:47 ingo Exp $
9 %
10 function export(wb, filename)
11
12 % get commands
13 wb.reset
14 cmds = {};
15 while awtinvoke(wb.mp, 'countReadyBlocks') > 0
16 cmds = [cmds wb.parseReadyBlocks()];
17 % move on
18 wb.skipForward();
19 end
20 wb.reset
21
22 if nargin == 2
23 % open output file
24 [path, fcnname, ext] = fileparts(filename);
25 fd = fopen(filename, 'w+');
26
27 % write header
28 plineName = char(awtinvoke(wb.mp, 'getActiveDiagramName'));
29 fprintf(fd, '%% Export of %s\n', plineName);
30 fprintf(fd, '%% \n');
31 fprintf(fd, '%% \n');
32 fprintf(fd, '%% %s\n', datestr(now));
33 fprintf(fd, '%% \n');
34 fprintf(fd, '%% \n');
35
36 fprintf(fd, 'function %s\n', strrep(fcnname, ' ', '_'));
37 for kk=1:numel(cmds)
38 fprintf(fd, '\t%s\n', cmds{kk});
39 end
40 fprintf(fd, 'end\n');
41
42 fclose(fd);
43 else
44 for kk=1:numel(cmds)
45 fprintf('%03d: %s\n', kk, cmds{kk});
46 end
47 end
48 end