0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 function cmds = hist2m(varargin)
0027
0028
0029 if utils.helper.isinfocall(varargin{:})
0030 cmds = getInfo(varargin{3});
0031 return
0032 end
0033
0034 import utils.const.*
0035 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0036
0037
0038
0039 CREATED2INT = 1e7;
0040
0041
0042 utils.helper.msg(msg.PROC1, 'extracting node list from history');
0043 [n,a, nodes] = getNodes(varargin{1}, [], 0, 1, []);
0044 utils.helper.msg(msg.PROC1, 'converting history nodes to commands');
0045
0046 i = 1;
0047 cmds = {};
0048 while i <= length(nodes)
0049 v = nodes(i).n;
0050 idx = find([nodes(:).pn] == i);
0051 pl = nodes(i).pl;
0052 aoName = mod(nodes(i).h.proctime,CREATED2INT);
0053 hi = [nodes(idx).h];
0054 iNames = zeros(size(hi));
0055 for j=1:length(hi)
0056 created = hi(j).proctime;
0057 iNames(j) = mod(created,CREATED2INT);
0058 end
0059 cmd = writeCmd(char(nodes(i).names), pl, aoName, iNames);
0060 utils.helper.msg(msg.PROC2, 'wrote command for node %d [%s]', i, char(nodes(i).names));
0061 cmds = [cmds cellstr(cmd)];
0062 i = i + 1;
0063 end
0064
0065
0066 utils.helper.msg(msg.PROC1, 'fixing duplicate commands');
0067 ncmds = length(cmds);
0068 for j = 1:ncmds
0069 cmdj = cmds{j};
0070
0071 for k = j+1:ncmds
0072 cmdk = cmds{k};
0073 if strcmp(cmdj, cmdk)
0074 cmds{j} = '';
0075 end
0076 end
0077 end
0078
0079 utils.helper.msg(msg.PROC1, 'writing output line');
0080
0081 alast = deblank(strtok(cmds{1}, '='));
0082 cmds = [cellstr(sprintf('a_out = %s;', alast)) cmds];
0083 end
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 function cmd = writeCmd(name, pl, aon, ains)
0097
0098 ainsStr = '';
0099
0100 ni = length(ains);
0101 for i=1:ni
0102 ainsStr = [ainsStr sprintf('a%d, ', ains(i))];
0103 end
0104
0105 name = strrep(name, '\_', '_');
0106
0107
0108 if isa(pl, 'plist')
0109 ps = writePlist(pl);
0110 else
0111 np = 0;
0112 ps = '';
0113 end
0114 if strcmp(ps, 'plist([])')
0115 ps = '';
0116 end
0117 pstr = deblank(sprintf('%s%s', ainsStr, ps));
0118
0119 if ~isempty(pstr)
0120 if pstr(end) == ','
0121 pstr = pstr(1:end-1);
0122 end
0123 end
0124 cmd = sprintf('a%d = %s(%s);', aon, name, pstr);
0125 end
0126
0127
0128
0129
0130
0131
0132
0133
0134 function ps = writePlist(pl)
0135
0136 ps = 'plist(';
0137 np = length(pl.params(:));
0138 for i=1:np
0139 p = pl.params(i);
0140
0141
0142
0143 if ischar(p.val)
0144 ps = [ps sprintf('''%s'', ''%s'',', p.key, p.val)];
0145
0146
0147 elseif isnumeric(p.val)
0148 ps = [ps [sprintf('''%s'', [', p.key) utils.helper.mat2str(p.val) '],']];
0149
0150
0151 elseif isa(p.val, 'specwin')
0152 w = p.val;
0153 wstr = string(w);
0154 ps = [ps sprintf('''%s'', %s,', p.key, wstr) ];
0155
0156
0157 elseif isa(p.val, 'pzmodel')
0158 pzm = p.val;
0159 fstr = string(pzm);
0160 ps = [ps sprintf('''%s'', %s,', p.key, fstr) ];
0161
0162
0163 elseif isa(p.val, 'time')
0164 tt = p.val;
0165 fstr = string(tt);
0166 ps = [ps sprintf('''%s'', %s,', p.key, fstr) ];
0167
0168
0169 elseif isa(p.val, 'provenance')
0170
0171
0172 elseif isa(p.val, 'history')
0173
0174
0175 elseif isa(p.val, 'plist')
0176 fstr = string(p.val);
0177 ps = [ps sprintf('%s', fstr) ];
0178
0179
0180 elseif isa(p.val, 'pz')
0181 fstr = string(p.val);
0182 ps = [ps sprintf('''%s'', %s,', p.key, fstr)];
0183
0184
0185 elseif isa(p.val, 'sym')
0186 fstr = char(p.val);
0187 ps = [ps sprintf('''%s'', sym(''%s''),', p.key, fstr)];
0188
0189
0190 elseif isa(p.val, 'ltpda_uo')
0191 f = p.val;
0192 fstr = string(f);
0193 ps = [ps sprintf('''%s'', %s,', p.key, fstr) ];
0194 elseif isa(p.val, 'unit')
0195 fstr = string(p.val);
0196 ps = [ps sprintf('''%s'', %s,', p.key, fstr)];
0197 elseif iscell(p.val)
0198 fstr = '{';
0199 for kk = 1: numel(p.val)
0200 if ischar(p.val{kk})
0201 fstr = sprintf('%s''%s'', ', fstr, p.val{kk});
0202 elseif isnumeric(p.val{kk})
0203 fstr = sprintf('%s[%s], ', fstr, utils.helper.mat2str(p.val{kk}));
0204 elseif isa(p.val{kk}, 'ltpda_obj')
0205 fstr = sprintf('%s%s, ', fstr, string(p.val{kk}));
0206 else
0207 error(['### unknown parameter type: ' p.key ' ' class(p.val{kk})]);
0208 end
0209 end
0210 if length(fstr) >= 3, fstr = fstr(1:end-2); end
0211 fstr = [fstr '}'];
0212 ps = [ps sprintf('''%s'', %s,', p.key, fstr) ];
0213
0214 else
0215 error(['### unknown parameter type: ' p.key ' ' class(p.val)]);
0216 end
0217
0218 end
0219 if ps(end) == ','
0220 ps = ps(1:end-1);
0221 end
0222 ps = [ps ')'];
0223 end
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236 function ii = getInfo(varargin)
0237 if nargin == 1 && strcmpi(varargin{1}, 'None')
0238 sets = {};
0239 pl = [];
0240 else
0241 sets = {'Default'};
0242 pl = getDefaultPlist;
0243 end
0244
0245 ii = minfo(mfilename, 'history', '', utils.const.categories.output, '$Id: hist2m.m,v 1.30 2008/09/05 14:17:16 hewitson Exp $', sets, pl);
0246 end
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259 function plo = getDefaultPlist()
0260 plo = plist();
0261 end
0262