Home > classes > @history > hist2m.m

hist2m

PURPOSE ^

HIST2M writes a new m-file that reproduces the analysis described in the

SYNOPSIS ^

function cmds = hist2m(h)

DESCRIPTION ^

 HIST2M writes a new m-file that reproduces the analysis described in the
 history object.
 
   >> cmds = hist2m(h);
 
 M Hewitson 06-02-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function cmds = hist2m(h)
0002 
0003 % HIST2M writes a new m-file that reproduces the analysis described in the
0004 % history object.
0005 %
0006 %   >> cmds = hist2m(h);
0007 %
0008 % M Hewitson 06-02-07
0009 %
0010 
0011 ALGONAME = mfilename;
0012 VERSION  = '$Id: hist2m.html,v 1.1 2007/06/08 14:15:05 hewitson Exp $';
0013 
0014 % get a node list
0015 [n,a, nodes] = getNodes(h, [], 0, 1, []);
0016 
0017 % loop over nodes and convert to commands
0018 i = 1;
0019 cmds = {};
0020 while i <= length(nodes)
0021   v = nodes(i).n;
0022   idx = find([nodes(:).pn] == i);
0023   pl = nodes(i).pl;  
0024   cmd = writeCmd(char(nodes(i).names), pl, i, idx);
0025   cmds = [cmds cellstr(cmd)];  
0026   i = i + 1;  
0027 end
0028 
0029 % now find commands that are duplicated after the '=' and remap those
0030 ncmds = length(cmds);
0031 for j = 1:ncmds
0032   cmdj = cmds{j};
0033   [tj,rj] = strtok(cmdj, '=');
0034   % now inspect all other commands prior to this one
0035   for k = j+1:ncmds
0036     cmdk = cmds{k};
0037     [tk,rk] = strtok(cmdk, '=');
0038     if strcmp(rj, rk)
0039       cmds{j} = [strtrim(tj) ' = ' strtrim(tk) ';'];
0040     end    
0041   end
0042 end
0043 
0044 %--------------------------------------------------------------------------
0045 %
0046 % write a command-line
0047 %
0048 function cmd = writeCmd(name, pl, aon, ains)
0049 
0050 ainsStr = '';
0051 % for i=length(ains):-1:1
0052 ni = length(ains);
0053 for i=1:ni
0054   ainsStr = [ainsStr sprintf('a%d, ', ains(i))];
0055 end
0056 
0057 name = strrep(name, '\_', '_');
0058 
0059 % look at the input parameters
0060 if isa(pl, 'plist')
0061   ps = writePlist(pl);
0062 else
0063   np = 0;
0064   ps = '';
0065 end
0066 if strcmp(ps, 'plist([])')
0067   ps = '';
0068 end
0069 pstr = deblank(sprintf('%s%s', ainsStr, ps));
0070 
0071 if ~isempty(pstr)
0072   if pstr(end) == ','
0073     pstr = pstr(1:end-1);
0074   end
0075 end
0076 cmd = sprintf('a%d = %s(%s);', aon, name, pstr);
0077 
0078 %-------------------------------------------------------
0079 function ps = writePlist(pl)
0080 
0081 ps = 'plist([';
0082 np = length(pl.params(:));
0083 for i=1:np
0084   p = pl.params(i);
0085   if ~isempty(p.val)
0086     if ischar(p.val)
0087       ps = [ps sprintf('param(''%s'', ''%s'') ', p.key, p.val)];
0088     elseif isnumeric(p.val)
0089       ps = [ps [sprintf('param(''%s'', [', p.key)  mat2str(p.val) ']) ']];
0090     elseif isa(p.val, 'specwin')
0091       w = p.val;
0092       wstr = string(w);
0093       ps = [ps sprintf('param(''%s'', %s) ', p.key, wstr) ];
0094     elseif isa(p.val, 'miir')
0095       f = p.val;
0096       fstr = string(f);
0097       ps = [ps sprintf('param(''%s'', %s) ', p.key, fstr) ];
0098     elseif isa(p.val, 'pzmodel')
0099       pzm = p.val;
0100       fstr = string(pzm);
0101       ps = [ps sprintf('param(''%s'', %s) ', p.key, fstr) ];
0102     else
0103       error(['### unknown parameter type: ' p.key '  ' p.val]);
0104     end
0105   end
0106 end
0107 ps = [ps '])'];
0108

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003