Home > classes > @ao > ao2m.m

ao2m

PURPOSE ^

AO2M converts an analysis object to an '.m' file based on the history contained in the analysis object.

SYNOPSIS ^

function varargout = ao2m(varargin)

DESCRIPTION ^

 AO2M converts an analysis object to an '.m' file based on the history contained in the analysis object.

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

 DESCRIPTION: AO2M converts an analysis object to an '.m' file based on the
              history contained in the analysis object.

 CALL:        ao2m(a, 'filename');
              ao2m(a, plist);
 
 
 PARAMETERS: 
 
           'filename'  - the filename to write to
 

 VERSION:     $Id: ao2m.m,v 1.14 2008/02/23 18:06:31 hewitson Exp $

 HISTORY: 08-02-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = ao2m(varargin)
0002 % AO2M converts an analysis object to an '.m' file based on the history contained in the analysis object.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: AO2M converts an analysis object to an '.m' file based on the
0007 %              history contained in the analysis object.
0008 %
0009 % CALL:        ao2m(a, 'filename');
0010 %              ao2m(a, plist);
0011 %
0012 %
0013 % PARAMETERS:
0014 %
0015 %           'filename'  - the filename to write to
0016 %
0017 %
0018 % VERSION:     $Id: ao2m.m,v 1.14 2008/02/23 18:06:31 hewitson Exp $
0019 %
0020 % HISTORY: 08-02-07 M Hewitson
0021 %             Creation
0022 %
0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 
0025 ALGONAME = mfilename;
0026 VERSION  = '$Id: ao2m.m,v 1.14 2008/02/23 18:06:31 hewitson Exp $';
0027 CATEGORY = 'Output';
0028 
0029 
0030 %% Check if this is a call for parameters
0031 if nargin == 2
0032   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0033     in = char(varargin{2});
0034     if strcmp(in, 'Params')
0035       varargout{1} = plist('filename', 'foo.m');
0036       return
0037     elseif strcmp(in, 'Version')
0038       varargout{1} = VERSION;
0039       return
0040     elseif strcmp(in, 'Category')
0041       varargout{1} = CATEGORY;
0042       return
0043     end
0044   end
0045 end
0046 
0047 
0048 
0049 %% Get inputs and proceed
0050 a        = varargin{1};
0051 % get filename from plist
0052 if isa(varargin{2}, 'plist')
0053   filename = find(varargin{2}, 'filename');
0054 else % or directly
0055   filename = varargin{2};
0056 end  
0057 if isempty(filename)
0058   error('### You must specify a filename. Either directly, or in a plist');
0059 end
0060 
0061 if length(a) > 1
0062   error('### I can only deal with one AO at a time.');
0063 end
0064 
0065 
0066 % clear this m-file from memory
0067 clear(filename);
0068 
0069 % convert the history to a set of commands
0070 cmds = hist2m(a.hist);
0071 
0072 % Now write output file
0073 [path,name,ext,vers] = fileparts(filename);
0074 if isempty(ext)
0075   filename = [filename '.m'];
0076 end
0077 if ~strcmp(ext, '.m')
0078   error('### I can only write .m files.');
0079 end
0080 
0081 d = a.data;
0082 fd = fopen(filename, 'w+');
0083 fprintf(fd, 'function a_out = %s\n\n', name);
0084 fprintf(fd, '%% %s \n', upper(filename));
0085 fprintf(fd, '%% \n');
0086 fprintf(fd, '%% \n');
0087 fprintf(fd, '%% written by %s / %s\n', ALGONAME, VERSION);
0088 fprintf(fd, '%% \n');
0089 fprintf(fd, '%% based on analysis object:\n');
0090 fprintf(fd, '%%            name: %s / %s\n', a.name, d.name);
0091 fprintf(fd, '%%      provenance: %s\n', char(a.provenance));
0092 fprintf(fd, '%%     description: %s\n', char(a.description));
0093 fprintf(fd, '%% original m-file: %s\n', a.mfilename);
0094 fprintf(fd, '%% \n');
0095 fprintf(fd, '%% \n');
0096 fprintf(fd, ' \n');
0097 fprintf(fd, ' \n');
0098 for c=length(cmds):-1:1
0099   if ~isempty(cmds{c})
0100     fprintf(fd, '%s\n', cmds{c});
0101   end
0102 end
0103 fprintf(fd, ' \n');
0104 fprintf(fd, ' \n');
0105 fprintf(fd, '%% END\n');
0106 
0107 fclose(fd);
0108 
0109 cd ('.');
0110 
0111

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003