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.30 2008/09/05 14:17:16 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.30 2008/09/05 14:17:16 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         %%%   symbolic math object   %%%
0185       elseif isa(p.val, 'sym')
0186         fstr = char(p.val);
0187         ps   = [ps sprintf('''%s'', sym(''%s''),', p.key, fstr)];
0188 
0189         %%%   ltpda_uo   %%%
0190       elseif isa(p.val, 'ltpda_uo')
0191         f = p.val;
0192         fstr = string(f);
0193         ps = [ps sprintf('''%s'', %s,', p.key, fstr) ];
0194       elseif isa(p.val, 'unit')
0195         fstr = string(p.val);
0196         ps   = [ps sprintf('''%s'', %s,', p.key, fstr)];
0197       elseif iscell(p.val)
0198         fstr = '{';
0199         for kk = 1: numel(p.val)
0200           if ischar(p.val{kk})
0201             fstr = sprintf('%s''%s'', ', fstr, p.val{kk});
0202           elseif isnumeric(p.val{kk})
0203             fstr = sprintf('%s[%s], ', fstr, utils.helper.mat2str(p.val{kk}));
0204           elseif isa(p.val{kk}, 'ltpda_obj')
0205             fstr = sprintf('%s%s, ', fstr, string(p.val{kk}));
0206           else
0207             error(['### unknown parameter type: ' p.key '  ' class(p.val{kk})]);
0208           end
0209         end
0210         if length(fstr) >= 3, fstr = fstr(1:end-2); end
0211         fstr = [fstr '}'];
0212         ps = [ps sprintf('''%s'', %s,', p.key, fstr) ];
0213 
0214       else
0215         error(['### unknown parameter type: ' p.key '  ' class(p.val)]);
0216       end
0217 %     end
0218   end
0219   if ps(end) == ','
0220     ps = ps(1:end-1);
0221   end
0222   ps = [ps ')'];
0223 end
0224 
0225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0226 %
0227 % FUNCTION:    getInfo
0228 %
0229 % DESCRIPTION: Get Info Object
0230 %
0231 % HISTORY:     11-07-07 M Hewitson
0232 %                Creation.
0233 %
0234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0235 
0236 function ii = getInfo(varargin)
0237   if nargin == 1 && strcmpi(varargin{1}, 'None')
0238     sets = {};
0239     pl   = [];
0240   else
0241     sets = {'Default'};
0242     pl   = getDefaultPlist;
0243   end
0244   % Build info object
0245   ii = minfo(mfilename, 'history', '', utils.const.categories.output, '$Id: hist2m.m,v 1.30 2008/09/05 14:17:16 hewitson Exp $', sets, pl);
0246 end
0247 
0248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0249 %
0250 % FUNCTION:    getDefaultPlist
0251 %
0252 % DESCRIPTION: Get Default Plist
0253 %
0254 % HISTORY:     11-07-07 M Hewitson
0255 %                Creation.
0256 %
0257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0258 
0259 function plo = getDefaultPlist()
0260   plo = plist();
0261 end
0262

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003