0001 function cmds = hist2m(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 ALGONAME = mfilename;
0023 VERSION = '$Id: hist2m.m,v 1.17 2008/02/22 22:28:48 hewitson Exp $';
0024 CATEGORY = 'Output';
0025
0026
0027 if nargin == 2
0028 if isa(varargin{1}, 'history') && ischar(varargin{2})
0029 in = char(varargin{1});
0030 if strcmp(in, 'Params')
0031 cmds = plist;
0032 return
0033 elseif strcmp(in, 'Version')
0034 cmds = VERSION;
0035 return
0036 elseif strcmp(in, 'Category')
0037 cmds = CATEGORY;
0038 return
0039 end
0040 end
0041 end
0042
0043
0044 h = varargin{1};
0045
0046
0047
0048 CREATED2INT = 1e7;
0049
0050
0051 disp(' -- extracting node list from history');
0052 [n,a, nodes] = getNodes(h, [], 0, 1, []);
0053
0054 disp(' -- converting history nodes to commands');
0055
0056 i = 1;
0057 cmds = {};
0058 while i <= length(nodes)
0059 v = nodes(i).n;
0060 idx = find([nodes(:).pn] == i);
0061 pl = nodes(i).pl;
0062 h = nodes(i).h;
0063 aoName = mod(h.created.utc_epoch_milli,CREATED2INT);
0064 hi = [nodes(idx).h];
0065 iNames = zeros(size(hi));
0066 for j=1:length(hi)
0067 created = hi(j).created;
0068 iNames(j) = mod(created.utc_epoch_milli,CREATED2INT);
0069 end
0070 cmd = writeCmd(char(nodes(i).names), pl, aoName, iNames);
0071 disp(sprintf(' -- wrote command for node %d [%s]', i, char(nodes(i).names)));
0072 cmds = [cmds cellstr(cmd)];
0073 i = i + 1;
0074 end
0075
0076
0077 disp(' -- fixing duplicate commands');
0078 ncmds = length(cmds);
0079 for j = 1:ncmds
0080 cmdj = cmds{j};
0081
0082 for k = j+1:ncmds
0083 cmdk = cmds{k};
0084 if strcmp(cmdj, cmdk)
0085 cmds{j} = '';
0086 end
0087 end
0088 end
0089
0090 disp(' -- writing output line');
0091
0092 alast = deblank(strtok(cmds{1}, '='));
0093 cmds = [cellstr(sprintf('a_out = %s;', alast)) cmds];
0094
0095
0096
0097
0098
0099 function cmd = writeCmd(name, pl, aon, ains)
0100
0101 ainsStr = '';
0102
0103 ni = length(ains);
0104 for i=1:ni
0105 ainsStr = [ainsStr sprintf('a%d, ', ains(i))];
0106 end
0107
0108 name = strrep(name, '\_', '_');
0109
0110
0111 if isa(pl, 'plist')
0112 ps = writePlist(pl);
0113 else
0114 np = 0;
0115 ps = '';
0116 end
0117 if strcmp(ps, 'plist([])')
0118 ps = '';
0119 end
0120 pstr = deblank(sprintf('%s%s', ainsStr, ps));
0121
0122 if ~isempty(pstr)
0123 if pstr(end) == ','
0124 pstr = pstr(1:end-1);
0125 end
0126 end
0127 cmd = sprintf('a%d = %s(%s);', aon, name, pstr);
0128
0129
0130
0131 function ps = writePlist(pl)
0132
0133 ps = 'plist([';
0134 np = length(pl.params(:));
0135 for i=1:np
0136 p = pl.params(i);
0137 if ~isempty(p.val)
0138
0139
0140 if ischar(p.val)
0141 ps = [ps sprintf('param(''%s'', ''%s'') ', p.key, p.val)];
0142
0143
0144 elseif isnumeric(p.val)
0145 ps = [ps [sprintf('param(''%s'', [', p.key) ltpda_mat2str(p.val) ']) ']];
0146
0147
0148 elseif isa(p.val, 'specwin')
0149 w = p.val;
0150 wstr = string(w);
0151 ps = [ps sprintf('param(''%s'', %s) ', p.key, wstr) ];
0152
0153
0154 elseif isa(p.val, 'miir')
0155 f = p.val;
0156 fstr = string(f);
0157 ps = [ps sprintf('param(''%s'', %s) ', p.key, fstr) ];
0158
0159
0160 elseif isa(p.val, 'pzmodel')
0161 pzm = p.val;
0162 fstr = string(pzm);
0163 ps = [ps sprintf('param(''%s'', %s) ', p.key, fstr) ];
0164
0165
0166 elseif isa(p.val, 'time')
0167 tt = p.val;
0168 fstr = string(tt);
0169 ps = [ps sprintf('param(''%s'', %s) ', p.key, fstr) ];
0170
0171
0172 elseif isa(p.val, 'provenance')
0173
0174
0175 elseif isa(p.val, 'history')
0176
0177
0178 elseif isa(p.val, 'plist')
0179 fstr = string(p.val);
0180 ps = [ps sprintf('%s', fstr) ];
0181 else
0182 error(['### unknown parameter type: ' p.key ' ' class(p.val)]);
0183 end
0184 end
0185 end
0186 ps = [ps '])'];
0187