Home > classes > @history > hist2m.m

hist2m

PURPOSE ^

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

SYNOPSIS ^

function cmds = hist2m(h)

DESCRIPTION ^

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: HIST2M writes a new m-file that reproduces the analysis described
              in the history object.

 CALL:        cmds = hist2m(h);

 INPUT:       h    - history object

 OUTPUT:      cmds - cell array with the commands to reproduce the data

 VERSION:     $Id: hist2m.m,v 1.13 2007/07/30 12:18:28 ingo Exp $

 HISTORY:     06-02-2007 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function cmds = hist2m(h)
0002 % HIST2M writes a new m-file that reproduces the analysis described in the history object.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: HIST2M writes a new m-file that reproduces the analysis described
0007 %              in the history object.
0008 %
0009 % CALL:        cmds = hist2m(h);
0010 %
0011 % INPUT:       h    - history object
0012 %
0013 % OUTPUT:      cmds - cell array with the commands to reproduce the data
0014 %
0015 % VERSION:     $Id: hist2m.m,v 1.13 2007/07/30 12:18:28 ingo Exp $
0016 %
0017 % HISTORY:     06-02-2007 M Hewitson
0018 %                 Creation
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 ALGONAME = mfilename;
0023 VERSION  = '$Id: hist2m.m,v 1.13 2007/07/30 12:18:28 ingo Exp $';
0024 
0025 % Created contains the epochtime in millisecounds and CREATED2INT define
0026 % the number of the last digits
0027 CREATED2INT = 1e7;
0028 
0029 % get a node list
0030 [n,a, nodes] = getNodes(h, [], 0, 1, []);
0031 
0032 % loop over nodes and convert to commands
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 %   cmd = writeCmd(char(nodes(i).names), pl, aoName, idx);
0049   cmds = [cmds cellstr(cmd)];
0050   i = i + 1;
0051 end
0052 
0053 % now find commands that are duplicated after the '=' and remap those
0054 ncmds = length(cmds);
0055 for j = 1:ncmds
0056   cmdj = cmds{j};
0057   % now inspect all other commands prior to this one
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 % add the final command to produce a_out
0067 alast = deblank(strtok(cmds{1}, '='));
0068 cmds  = [cellstr(sprintf('a_out = %s;', alast)) cmds];
0069 
0070 %--------------------------------------------------------------------------
0071 %
0072 % write a command-line
0073 %
0074 function cmd = writeCmd(name, pl, aon, ains)
0075 
0076 ainsStr = '';
0077 % for i=length(ains):-1:1
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 % look at the input parameters
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

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003