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 if ~isempty(p.val)
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, 'ltpda_uo')
0186 f = p.val;
0187 fstr = string(f);
0188 ps = [ps sprintf('''%s'', %s,', p.key, fstr) ];
0189
0190 elseif isa(p.val, 'sym')
0191 ps = [ps sprintf('''%s'', ''%s'',', p.key, char(p.val))];
0192 elseif iscell(p.val)
0193 fstr = '{';
0194 for kk = 1: numel(p.val)
0195 if ischar(p.val{kk})
0196 fstr = sprintf('%s''%s'', ', fstr, p.val{kk});
0197 elseif isnumeric(p.val{kk})
0198 fstr = sprintf('%s[%s], ', fstr, utils.helper.mat2str(p.val{kk}));
0199 elseif isa(p.val{kk}, 'ltpda_obj')
0200 fstr = sprintf('%s%s, ', fstr, string(p.val{kk}));
0201 else
0202 error(['### unknown parameter type: ' p.key ' ' class(p.val{kk})]);
0203 end
0204 end
0205 if length(fstr) >= 3, fstr = fstr(1:end-2); end
0206 fstr = [fstr '}'];
0207 ps = [ps sprintf('''%s'', %s,', p.key, fstr) ];
0208
0209 else
0210 error(['### unknown parameter type: ' p.key ' ' class(p.val)]);
0211 end
0212 end
0213 end
0214 if ps(end) == ','
0215 ps = ps(1:end-1);
0216 end
0217 ps = [ps ')'];
0218 end
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231 function ii = getInfo(varargin)
0232 if nargin == 1 && strcmpi(varargin{1}, 'None')
0233 sets = {};
0234 pl = [];
0235 else
0236 sets = {'Default'};
0237 pl = getDefaultPlist;
0238 end
0239
0240 ii = minfo(mfilename, 'history', '', 'Output', '$Id: hist2m.m,v 1.25 2008/08/25 19:41:33 hewitson Exp $', sets, pl);
0241 end
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254 function plo = getDefaultPlist()
0255 plo = plist();
0256 end
0257