Home > classes > @ltpda_uoh > type.m

type

PURPOSE ^

TYPE converts the input objects to MATLAB functions.

SYNOPSIS ^

function varargout = type(varargin)

DESCRIPTION ^

 TYPE converts the input objects to MATLAB functions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: TYPE converts the input objects to MATLAB functions that
              reproduce the processing steps that led to the input objects.

 CALL:        type(as)
              type(as, 'filename')
              type(as, plist)

 INPUTS:      as  - array of ltpda_uoh objects
              pl  - parameter list (see below)

 OUTPUTS:     none.

 PARAMETER LIST:

              'filename' - specify the filename to write the commands in.
 
 M-FILE INFO: Get information about this methods by calling
              >> <ltpda_uoh>.getInfo('type')

              Get information about a specified set-plist by calling:
              >> <ltpda_uoh>.getInfo('type', 'None')

     example: ao.getInfo('type') 
 
 VERSION:     $Id: type.m,v 1.5 2008/09/04 15:29:30 ingo Exp $

 HISTORY:     02-02-07 M Hewitson
                 Created

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % TYPE converts the input objects to MATLAB functions.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: TYPE converts the input objects to MATLAB functions that
0005 %              reproduce the processing steps that led to the input objects.
0006 %
0007 % CALL:        type(as)
0008 %              type(as, 'filename')
0009 %              type(as, plist)
0010 %
0011 % INPUTS:      as  - array of ltpda_uoh objects
0012 %              pl  - parameter list (see below)
0013 %
0014 % OUTPUTS:     none.
0015 %
0016 % PARAMETER LIST:
0017 %
0018 %              'filename' - specify the filename to write the commands in.
0019 %
0020 % M-FILE INFO: Get information about this methods by calling
0021 %              >> <ltpda_uoh>.getInfo('type')
0022 %
0023 %              Get information about a specified set-plist by calling:
0024 %              >> <ltpda_uoh>.getInfo('type', 'None')
0025 %
0026 %     example: ao.getInfo('type')
0027 %
0028 % VERSION:     $Id: type.m,v 1.5 2008/09/04 15:29:30 ingo Exp $
0029 %
0030 % HISTORY:     02-02-07 M Hewitson
0031 %                 Created
0032 %
0033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0034 
0035 function varargout = type(varargin)
0036 
0037   import utils.const.*
0038   
0039   % Check if this is a call for parameters
0040   if utils.helper.isinfocall(varargin{:})
0041     varargout{1} = getInfo(varargin{3});
0042     return
0043   end
0044 
0045   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0046   
0047   % Collect input variable names
0048   in_names = cell(size(varargin));
0049   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0050 
0051   % Collect all AOs and plists
0052   [as, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ltpda_uoh', in_names);
0053   [pl, pl_invars, rest] = utils.helper.collect_objects(rest, 'plist', in_names);
0054 
0055   % Combine plists
0056   pl = combine(pl, getDefaultPlist);
0057   filename = find(pl, 'filename');
0058 
0059   % Check for filename
0060   if isempty(filename)
0061     if ~isempty(rest)
0062       if strcmp(rest{1}(end-1:end), '.m')
0063         filename = rest{1};
0064       else
0065         filename = fullfile(rest{1}, '.m');
0066       end
0067     end
0068   end
0069     
0070   % Go through each input AO
0071   for j=1:numel(as)  
0072     
0073     % convert to commands
0074     fcn(j).cmds = hist2m(as(j).hist);
0075     
0076   end % End AO loop
0077   
0078   %----- Output to screen
0079   if isempty(filename)
0080     
0081     for j=1:numel(fcn)
0082       % Header
0083       LL = 25;
0084       disp(utils.prog.strpad('', [LL LL], '-'));
0085       disp(utils.prog.strpad(as(j).name, [LL LL], '-'));
0086       disp(utils.prog.strpad('', [LL LL], '-'));
0087       disp(' ');
0088       
0089       % Print each command
0090       for k=numel(fcn(j).cmds):-1:1
0091         disp(fcn(j).cmds{k})
0092       end
0093       
0094       % Footer
0095       disp(' ');
0096       disp(utils.prog.strpad('', [LL LL], '-'));
0097       disp(utils.prog.strpad(as(j).name, [LL LL], '-'));
0098       disp(utils.prog.strpad('', [LL LL], '-'));
0099       disp(' ');
0100     end
0101     
0102   %----- Output to file
0103   else
0104     
0105     % clear this m-file from memory
0106     clear(filename);
0107   
0108     % Open the file
0109     ii = getInfo;
0110     fd = fopen(filename, 'w+');
0111     [path,name,ext,vers] = fileparts(filename);
0112     
0113     % Write help header
0114     fprintf(fd, '%% %s \n', upper(filename));
0115     fprintf(fd, '%% \n');
0116     fprintf(fd, '%% \n');
0117     fprintf(fd, '%% written by %s / %s\n', mfilename, ii.mversion);
0118     fprintf(fd, '%% \n');
0119     fprintf(fd, '%% \n');
0120     fprintf(fd, ' \n');
0121     fprintf(fd, ' \n');
0122     
0123     % write main fcn
0124     fprintf(fd, 'function out = %s\n\n', name);
0125     fprintf(fd, 'out = [];\n');
0126     for j=1:numel(as)
0127       fprintf(fd, 'out = [out obj%03d];\n', j);
0128     end
0129     fprintf(fd, '\nend\n\n');
0130     
0131     % Write each sub function
0132     for kk=1:numel(fcn)
0133       % header
0134       fprintf(fd, '%% sub-function for object %s\n', as(kk).name);
0135       fprintf(fd, 'function a_out = obj%03d\n\n', kk);
0136       % write command for this function
0137       for jj=numel(fcn(kk).cmds):-1:1
0138         fprintf(fd, '\t%s\n', fcn(kk).cmds{jj});
0139       end
0140       % Footer
0141       fprintf(fd, '\nend\n\n');
0142     end
0143     
0144     fprintf(fd, '\n\n%% END\n');
0145     
0146     % Close file
0147     fclose(fd);
0148     % This somehow forces the new file to be available to MATLAB
0149     cd ('.');
0150   end
0151 
0152 end
0153 
0154 %--------------------------------------------------------------------------
0155 % Get Info Object
0156 %--------------------------------------------------------------------------
0157 function ii = getInfo(varargin)
0158   if nargin == 1 && strcmpi(varargin{1}, 'None')
0159     sets = {};
0160     pl   = [];
0161   else
0162     sets = {'Default'};
0163     pl   = getDefaultPlist;
0164   end
0165   % Build info object
0166   ii = minfo(mfilename, 'ao', '', utils.const.categories.output, '$Id: type.m,v 1.5 2008/09/04 15:29:30 ingo Exp $', sets, pl);
0167 end
0168 
0169 %--------------------------------------------------------------------------
0170 % Get Default Plist
0171 %--------------------------------------------------------------------------
0172 function pl = getDefaultPlist()
0173   pl = plist('filename', '');
0174 end
0175 
0176 
0177 
0178 % END

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