Mercurial > hg > ltpda
comparison m-toolbox/classes/@history/hist2m.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 % HIST2M writes a new m-file that reproduces the analysis described in the history object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: HIST2M writes a new m-file that reproduces the analysis described | |
5 % in the history object. | |
6 % | |
7 % CALL: cmds = hist2m(h); | |
8 % | |
9 % INPUT: h - history object | |
10 % | |
11 % OUTPUT: cmds - cell array with the commands to reproduce the data | |
12 % | |
13 % VERSION: $Id: hist2m.m,v 1.49 2011/03/29 13:40:16 hewitson Exp $ | |
14 % | |
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
16 | |
17 function cmds = hist2m(varargin) | |
18 | |
19 import utils.const.* | |
20 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
21 | |
22 % Get history objects | |
23 hists = varargin{1}; | |
24 | |
25 if nargin >= 2 | |
26 pl = combine(varargin{2}, getDefaultPlist()); | |
27 else | |
28 pl = getDefaultPlist(); | |
29 end | |
30 | |
31 % Created contains the epochtime in millisecounds and CREATED2INT define | |
32 % the number of the last digits | |
33 CREATED2INT = 1e7; | |
34 | |
35 % get a node list | |
36 utils.helper.msg(msg.PROC1, 'extracting node list from history'); | |
37 [n,a, nodes] = getNodes(hists, pl.find('stop_option')); | |
38 utils.helper.msg(msg.PROC1, 'converting history nodes to commands'); | |
39 % loop over nodes and convert to commands | |
40 i = 1; | |
41 cmds = {}; | |
42 while i <= length(nodes) | |
43 v = nodes(i).n; | |
44 idx = find([nodes(:).pn] == i); | |
45 pl = nodes(i).pl; | |
46 aoName = mod(nodes(i).h.proctime,CREATED2INT); | |
47 hi = [nodes(idx).h]; | |
48 iNames = zeros(size(hi)); | |
49 for j=1:length(hi) | |
50 created = hi(j).proctime; %get(hi(j), 'created'); | |
51 iNames(j) = mod(created,CREATED2INT); | |
52 end | |
53 cmd = writeCmd(char(nodes(i).names), pl, aoName, iNames, nodes(i).h.methodInfo.mclass); | |
54 if ~iscell(cmd), cmd = {cmd}; end | |
55 utils.helper.msg(msg.PROC2, 'wrote command for node %d [%s]', i, char(nodes(i).names)); | |
56 for kk=1:numel(cmd) | |
57 utils.helper.msg(msg.PROC3, 'command: %s', cmd{kk}); | |
58 end | |
59 cmds = {cmds{:} cmd{:}}; | |
60 i = i + 1; | |
61 end | |
62 | |
63 % now find commands that are duplicated after the '=' and remap those | |
64 utils.helper.msg(msg.PROC1, 'fixing duplicate commands'); | |
65 ncmds = length(cmds); | |
66 for j = 1:ncmds | |
67 cmdj = cmds{j}; | |
68 % now inspect all other commands prior to this one | |
69 for k = j+1:ncmds | |
70 cmdk = cmds{k}; | |
71 if strcmp(cmdj, cmdk) | |
72 cmds{j} = ''; | |
73 end | |
74 end | |
75 end | |
76 % remove empty commands | |
77 cmds = cmds(~strcmp('', cmds)); | |
78 | |
79 utils.helper.msg(msg.PROC1, 'writing output line'); | |
80 % add the final command to produce a_out | |
81 alast = deblank(strtok(cmds{1}, '=')); | |
82 cmds = [cellstr(sprintf('a_out = %s;', alast)) cmds]; | |
83 end | |
84 | |
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
86 % Local Functions % | |
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
88 | |
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
90 % % | |
91 % FUNCTION: writeCmd % | |
92 % % | |
93 % DESCRIPTION: write a command-line % | |
94 % % | |
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
96 | |
97 function cmd = writeCmd(name, pl, aon, ains,methodclass) | |
98 | |
99 ainsStr = ''; | |
100 % for i=length(ains):-1:1 | |
101 ni = length(ains); | |
102 for i=1:ni | |
103 ainsStr = [ainsStr sprintf('a%d, ', ains(i))]; | |
104 end | |
105 | |
106 name = strrep(name, '\_', '_'); | |
107 | |
108 if ~isempty(pl) | |
109 % convert plist to commands | |
110 cmd = plist2cmds(pl); | |
111 % the last command will go as input to the method command | |
112 [s,plstr] = strtok(cmd{1}); | |
113 plstr = strtrim(plstr); | |
114 cmd = [ sprintf('a%d = %s(%s%s); %% %s', ... | |
115 aon, name, ainsStr, strtrim(plstr(2:end-1)),methodclass) cmd(2:end)]; | |
116 else | |
117 ainsStr = ainsStr(1:end-2); | |
118 cmd = sprintf('a%d = %s(%s);', aon, name, ainsStr); | |
119 end | |
120 | |
121 end | |
122 | |
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
124 % | |
125 % FUNCTION: getDefaultPlist | |
126 % | |
127 % DESCRIPTION: Get Default Plist | |
128 % | |
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
130 | |
131 function plo = getDefaultPlist() | |
132 plo = plist('stop_option', 'full'); | |
133 end | |
134 |