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(varargin)

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

 M-FILE INFO: Get information about this methods by calling
              >> history.getInfo('hist2m')

              Get information about a specified set-plist by calling:
              >> history.getInfo('hist2m', 'set')

 VERSION:     $Id: hist2m.m,v 1.25 2008/08/25 19:41:33 hewitson Exp $

 HISTORY:     06-02-2007 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % HIST2M writes a new m-file that reproduces the analysis described in the history object.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: HIST2M writes a new m-file that reproduces the analysis described
0005 %              in the history object.
0006 %
0007 % CALL:        cmds = hist2m(h);
0008 %
0009 % INPUT:       h    - history object
0010 %
0011 % OUTPUT:      cmds - cell array with the commands to reproduce the data
0012 %
0013 % M-FILE INFO: Get information about this methods by calling
0014 %              >> history.getInfo('hist2m')
0015 %
0016 %              Get information about a specified set-plist by calling:
0017 %              >> history.getInfo('hist2m', 'set')
0018 %
0019 % VERSION:     $Id: hist2m.m,v 1.25 2008/08/25 19:41:33 hewitson Exp $
0020 %
0021 % HISTORY:     06-02-2007 M Hewitson
0022 %                 Creation
0023 %
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 function cmds = hist2m(varargin)
0027 
0028   %%% Check if this is a call for parameters
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   % Created contains the epochtime in millisecounds and CREATED2INT define
0038   % the number of the last digits
0039   CREATED2INT = 1e7;
0040 
0041   % get a node list
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   % loop over nodes and convert to commands
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; %get(hi(j), 'created');
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   % now find commands that are duplicated after the '=' and remap those
0066   utils.helper.msg(msg.PROC1, 'fixing duplicate commands');
0067   ncmds = length(cmds);
0068   for j = 1:ncmds
0069     cmdj = cmds{j};
0070     % now inspect all other commands prior to this one
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   % add the final command to produce a_out
0081   alast = deblank(strtok(cmds{1}, '='));
0082   cmds  = [cellstr(sprintf('a_out = %s;', alast)) cmds];
0083 end
0084 
0085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0086 %                               Local Functions                               %
0087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0088 
0089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0090 %                                                                             %
0091 % FUNCTION:    writeCmd                                                       %
0092 %                                                                             %
0093 % DESCRIPTION: write a command-line                                           %
0094 %                                                                             %
0095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0096 function cmd = writeCmd(name, pl, aon, ains)
0097 
0098   ainsStr = '';
0099   % for i=length(ains):-1:1
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   % look at the input parameters
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 % FUNCTION:    writePlist                                                     %
0130 %                                                                             %
0131 % DESCRIPTION: write a plist                                                  %
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       %%%   char   %%%
0143       if ischar(p.val)
0144         ps = [ps sprintf('''%s'', ''%s'',', p.key, p.val)];
0145 
0146         %%%   numeric   %%%
0147       elseif isnumeric(p.val)
0148         ps = [ps [sprintf('''%s'', [', p.key)  utils.helper.mat2str(p.val) '],']];
0149 
0150         %%%   specwin   %%%
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         %%%   pzmodel   %%%
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         %%%   time   %%%
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         %%%   provenance   %%%
0169       elseif isa(p.val, 'provenance')
0170 
0171         %%%   history   %%%
0172       elseif isa(p.val, 'history')
0173 
0174         %%%   plist   %%%
0175       elseif isa(p.val, 'plist')
0176         fstr = string(p.val);
0177         ps = [ps sprintf('%s', fstr) ];
0178 
0179         %%%   pz-object   %%%
0180       elseif isa(p.val, 'pz')
0181         fstr = string(p.val);
0182         ps   = [ps sprintf('''%s'', %s,', p.key, fstr)];
0183 
0184         %%%   ltpda_uo   %%%
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 % FUNCTION:    getInfo
0223 %
0224 % DESCRIPTION: Get Info Object
0225 %
0226 % HISTORY:     11-07-07 M Hewitson
0227 %                Creation.
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   % Build info object
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 % FUNCTION:    getDefaultPlist
0246 %
0247 % DESCRIPTION: Get Default Plist
0248 %
0249 % HISTORY:     11-07-07 M Hewitson
0250 %                Creation.
0251 %
0252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0253 
0254 function plo = getDefaultPlist()
0255   plo = plist();
0256 end
0257

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003