0001 function cmds = hist2m(h)
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.13 2007/07/30 12:18:28 ingo Exp $';
0024
0025
0026
0027 CREATED2INT = 1e7;
0028
0029
0030 [n,a, nodes] = getNodes(h, [], 0, 1, []);
0031
0032
0033 i = 1;
0034 cmds = {};
0035 while i <= length(nodes)
0036 v = nodes(i).n;
0037 idx = find([nodes(:).pn] == i);
0038 pl = nodes(i).pl;
0039 h = nodes(i).h;
0040 aoName = mod(get(h.created, 'utc_epoch_milli'),CREATED2INT);
0041 hi = [nodes(idx).h];
0042 iNames = zeros(size(hi));
0043 for j=1:length(hi)
0044 created = get(hi(j), 'created');
0045 iNames(j) = mod(get(created, 'utc_epoch_milli'),CREATED2INT);
0046 end
0047 cmd = writeCmd(char(nodes(i).names), pl, aoName, iNames);
0048
0049 cmds = [cmds cellstr(cmd)];
0050 i = i + 1;
0051 end
0052
0053
0054 ncmds = length(cmds);
0055 for j = 1:ncmds
0056 cmdj = cmds{j};
0057
0058 for k = j+1:ncmds
0059 cmdk = cmds{k};
0060 if strcmp(cmdj, cmdk)
0061 cmds{j} = '';
0062 end
0063 end
0064 end
0065
0066
0067 alast = deblank(strtok(cmds{1}, '='));
0068 cmds = [cellstr(sprintf('a_out = %s;', alast)) cmds];
0069
0070
0071
0072
0073
0074 function cmd = writeCmd(name, pl, aon, ains)
0075
0076 ainsStr = '';
0077
0078 ni = length(ains);
0079 for i=1:ni
0080 ainsStr = [ainsStr sprintf('a%d, ', ains(i))];
0081 end
0082
0083 name = strrep(name, '\_', '_');
0084
0085
0086 if isa(pl, 'plist')
0087 ps = writePlist(pl);
0088 else
0089 np = 0;
0090 ps = '';
0091 end
0092 if strcmp(ps, 'plist([])')
0093 ps = '';
0094 end
0095 pstr = deblank(sprintf('%s%s', ainsStr, ps));
0096
0097 if ~isempty(pstr)
0098 if pstr(end) == ','
0099 pstr = pstr(1:end-1);
0100 end
0101 end
0102 cmd = sprintf('a%d = %s(%s);', aon, name, pstr);
0103
0104
0105
0106 function ps = writePlist(pl)
0107
0108 ps = 'plist([';
0109 np = length(pl.params(:));
0110 for i=1:np
0111 p = pl.params(i);
0112 if ~isempty(p.val)
0113 if ischar(p.val)
0114 ps = [ps sprintf('param(''%s'', ''%s'') ', p.key, p.val)];
0115 elseif isnumeric(p.val)
0116 ps = [ps [sprintf('param(''%s'', [', p.key) ltpda_mat2str(p.val) ']) ']];
0117 elseif isa(p.val, 'specwin')
0118 w = p.val;
0119 wstr = string(w);
0120 ps = [ps sprintf('param(''%s'', %s) ', p.key, wstr) ];
0121 elseif isa(p.val, 'miir')
0122 f = p.val;
0123 fstr = string(f);
0124 ps = [ps sprintf('param(''%s'', %s) ', p.key, fstr) ];
0125 elseif isa(p.val, 'pzmodel')
0126 pzm = p.val;
0127 fstr = string(pzm);
0128 ps = [ps sprintf('param(''%s'', %s) ', p.key, fstr) ];
0129 else
0130 error(['### unknown parameter type: ' p.key ' ' p.val]);
0131 end
0132 end
0133 end
0134 ps = [ps '])'];
0135