Home > classes > @ao > ao.m

ao

PURPOSE ^

AO analysis object class constructor.

SYNOPSIS ^

function varargout = ao(varargin)

DESCRIPTION ^

 AO analysis object class constructor.

     Create an analysis object.

     Properties:
       tag        - unique ID tag. (always -1 before submission to AO Repository)
       name       - name of analysis object
       data       - data object (tsdata, fsdata)
       history    - history object
       provenance - creation info, machine, user, etc


     Possible constructors:

       a = ao()            - creates an empty analysis object
       a = ao('a1.xml')    - creates a new analysis object by loading the
                             analysis object from disk.
       a = ao('file.txt')  - creates a new analysis object by loading the
       a = ao('file.dat')    data in 'file.txt'. The ascii file is assumed
                             to be an equally sampled two-column file of
                             time and amplitude. By default, the amplitude
                             units are taken to be Volts ('V') and the
                             time samples are assumed to be in seconds.
       a = ao('file',pl)   - creates a new analysis object by loading the
                             data in 'file'. The parameter list decide how the
                             analysis object is created. The valid key values
                             of the parameter list are:
                             'type'        'tsdata','fsdata','xydata'
                                            default = 'tsdata'
                             'use_fs'       if this value is set, the
                                            x-axes is computed by the fs value.
                             'columns'      [1 2 1 4]
                                            default = [1 2]
                                            Each pair represented the x- and y-axes.
                                            (Each column pair creates an analysis object)
                                            Is the value 'use_fs' is used then
                                            represent each column the y-axes.
                                            (Each column creates an analysis object)
                             'num_columns'  Maximum colums in the file
                                            default = 10
                             'comment_char' The comment character in the file
                                            default = '%'
                             'comment'      To set the comment in the analysis object
                             '...'          every property of the data object
                                            e.g. 'name'
                             If the constructor creates multiple ao's it is
                             possible to give each data class its own e.g.
                             'name'. In this case the parameter list with the
                             key 'name' must have cell of the different values
                             as the name of the different data objects. e.g.
                             pl = plist('columns', [1 2 1 3],        ...
                                        'name',   {'name1' 'name2'}, ...
                                        'xunits', 'sec',             ...
                                        'yunits', {'V' 'Hz'});
                             This parameter list creates two ao's with tsdata.
       a = ao(plist)       - creates an analysis object with by reading
                             the file specified by the 'filename'
                             parameter in the plist.
       a = ao(data)        - creates an analysis object with a data
                             object. Data object can be one of tsdata,
                             fsdata.
       a = ao(data, hist)  - creates an analysis object with a data
                             object and a history object

       a = ao(specwin)     - creates an analysis object from a specwin
                             object

 Parameters for plist constructor:

   'filename' - construct an AO from a filename.
                Example: plist(param('filename', 'a1.xml'))

   'fcn'      - construct an AO from some valid MATLAB function.
                Example: plist(param('fcn', 'randn(100)'))

   'vals'     - construct an AO from a set of values.
                Example: plist(param('vals', [1 2 3]))

   'tsfcn'    - construct an AO from a function of time. You need to also
                specify parameters 'fs' and 'nsecs' for this call.
                Example:
                  plist([param('fs', 10) param('nsecs', 10) param('tsfcn',
                  'sin(2*pi*1.4*t) + 0.1*randn(size(t))')])

   'win'      - construct an AO from a specwin window function. Tjis
                creates a cdata type AO containing the window values.
                Example: plist(param('win', specwin('Hannning', 100)))

   'waveform' - construct an AO from a waveform description. Here you need
                to specify additional parameters 'fs' and 'nsecs', and also,
                for the following waveform types:
                'sine wave'      - 'f', 'phi'
                'noise'          - 'type' (can be 'Normal' or 'Uniform')
                'chirp'          - 'f0', 'f1', 't1'      (help chirp)
                'Gaussian pulse' - 'f0', 'bw'            (help gauspuls)
                'Square wave'    - 'f', 'duty'           (help square)
                'Sawtooth'       - 'f', 'width'          (help sawtooth)

     Indexing:
       b = a(1)            % where a is an array of analysis objects
       d = a.data;         % get the data object
       h = a.hist;         % get the history object
       d = a.data.x(1:20); % get a matrix of data values x;

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = ao(ao, 'Params')


 See also tsdata, fsdata, xydata, cdata

 M Hewitson 30-01-07

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = ao(varargin)
0002 % AO analysis object class constructor.
0003 %
0004 %     Create an analysis object.
0005 %
0006 %     Properties:
0007 %       tag        - unique ID tag. (always -1 before submission to AO Repository)
0008 %       name       - name of analysis object
0009 %       data       - data object (tsdata, fsdata)
0010 %       history    - history object
0011 %       provenance - creation info, machine, user, etc
0012 %
0013 %
0014 %     Possible constructors:
0015 %
0016 %       a = ao()            - creates an empty analysis object
0017 %       a = ao('a1.xml')    - creates a new analysis object by loading the
0018 %                             analysis object from disk.
0019 %       a = ao('file.txt')  - creates a new analysis object by loading the
0020 %       a = ao('file.dat')    data in 'file.txt'. The ascii file is assumed
0021 %                             to be an equally sampled two-column file of
0022 %                             time and amplitude. By default, the amplitude
0023 %                             units are taken to be Volts ('V') and the
0024 %                             time samples are assumed to be in seconds.
0025 %       a = ao('file',pl)   - creates a new analysis object by loading the
0026 %                             data in 'file'. The parameter list decide how the
0027 %                             analysis object is created. The valid key values
0028 %                             of the parameter list are:
0029 %                             'type'        'tsdata','fsdata','xydata'
0030 %                                            default = 'tsdata'
0031 %                             'use_fs'       if this value is set, the
0032 %                                            x-axes is computed by the fs value.
0033 %                             'columns'      [1 2 1 4]
0034 %                                            default = [1 2]
0035 %                                            Each pair represented the x- and y-axes.
0036 %                                            (Each column pair creates an analysis object)
0037 %                                            Is the value 'use_fs' is used then
0038 %                                            represent each column the y-axes.
0039 %                                            (Each column creates an analysis object)
0040 %                             'num_columns'  Maximum colums in the file
0041 %                                            default = 10
0042 %                             'comment_char' The comment character in the file
0043 %                                            default = '%'
0044 %                             'comment'      To set the comment in the analysis object
0045 %                             '...'          every property of the data object
0046 %                                            e.g. 'name'
0047 %                             If the constructor creates multiple ao's it is
0048 %                             possible to give each data class its own e.g.
0049 %                             'name'. In this case the parameter list with the
0050 %                             key 'name' must have cell of the different values
0051 %                             as the name of the different data objects. e.g.
0052 %                             pl = plist('columns', [1 2 1 3],        ...
0053 %                                        'name',   {'name1' 'name2'}, ...
0054 %                                        'xunits', 'sec',             ...
0055 %                                        'yunits', {'V' 'Hz'});
0056 %                             This parameter list creates two ao's with tsdata.
0057 %       a = ao(plist)       - creates an analysis object with by reading
0058 %                             the file specified by the 'filename'
0059 %                             parameter in the plist.
0060 %       a = ao(data)        - creates an analysis object with a data
0061 %                             object. Data object can be one of tsdata,
0062 %                             fsdata.
0063 %       a = ao(data, hist)  - creates an analysis object with a data
0064 %                             object and a history object
0065 %
0066 %       a = ao(specwin)     - creates an analysis object from a specwin
0067 %                             object
0068 %
0069 % Parameters for plist constructor:
0070 %
0071 %   'filename' - construct an AO from a filename.
0072 %                Example: plist(param('filename', 'a1.xml'))
0073 %
0074 %   'fcn'      - construct an AO from some valid MATLAB function.
0075 %                Example: plist(param('fcn', 'randn(100)'))
0076 %
0077 %   'vals'     - construct an AO from a set of values.
0078 %                Example: plist(param('vals', [1 2 3]))
0079 %
0080 %   'tsfcn'    - construct an AO from a function of time. You need to also
0081 %                specify parameters 'fs' and 'nsecs' for this call.
0082 %                Example:
0083 %                  plist([param('fs', 10) param('nsecs', 10) param('tsfcn',
0084 %                  'sin(2*pi*1.4*t) + 0.1*randn(size(t))')])
0085 %
0086 %   'win'      - construct an AO from a specwin window function. Tjis
0087 %                creates a cdata type AO containing the window values.
0088 %                Example: plist(param('win', specwin('Hannning', 100)))
0089 %
0090 %   'waveform' - construct an AO from a waveform description. Here you need
0091 %                to specify additional parameters 'fs' and 'nsecs', and also,
0092 %                for the following waveform types:
0093 %                'sine wave'      - 'f', 'phi'
0094 %                'noise'          - 'type' (can be 'Normal' or 'Uniform')
0095 %                'chirp'          - 'f0', 'f1', 't1'      (help chirp)
0096 %                'Gaussian pulse' - 'f0', 'bw'            (help gauspuls)
0097 %                'Square wave'    - 'f', 'duty'           (help square)
0098 %                'Sawtooth'       - 'f', 'width'          (help sawtooth)
0099 %
0100 %     Indexing:
0101 %       b = a(1)            % where a is an array of analysis objects
0102 %       d = a.data;         % get the data object
0103 %       h = a.hist;         % get the history object
0104 %       d = a.data.x(1:20); % get a matrix of data values x;
0105 %
0106 % The following call returns a parameter list object that contains the
0107 % default parameter values:
0108 %
0109 % >> pl = ao(ao, 'Params')
0110 %
0111 %
0112 % See also tsdata, fsdata, xydata, cdata
0113 %
0114 % M Hewitson 30-01-07
0115 %
0116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0117 
0118 %       a = ao('object.mat') - creates a new analysis object by loading the
0119 %                             analysis object from disk .
0120 
0121 ALGONAME = mfilename;
0122 VERSION  = '$Id: ao.m,v 1.46 2007/10/22 11:52:19 ingo Exp $';
0123 
0124 % Is this a 'Params' call?
0125 if  nargin == 2 &&...
0126     isa(varargin{1}, 'ao') &&...
0127     strcmp(varargin{2}, 'Params')
0128 
0129   varargout{1} = plist();
0130   return
0131 end
0132 
0133 % process input arguments
0134 args = [];
0135 k = 0;
0136 pls = [];
0137 for j=1:nargin
0138   if ~isempty(varargin{j})
0139     k = k + 1;
0140     if isa(varargin{j}, 'plist')
0141       pls = [pls varargin{j}];
0142     else
0143       args(k).val = varargin{j};
0144       args(k).n   = j;
0145     end
0146   end
0147 end
0148 
0149 % We could have multiple input plist objects. Combine them here.
0150 if isa(pls, 'plist')
0151   pl = combine(pls);
0152 else
0153   pl = [];
0154 end
0155 
0156 Nargs = length(args);
0157 if ~isempty(pl)
0158   args(Nargs+1).val = pl;
0159   args(Nargs+1).n   = j+1;
0160   Nargs = length(args);
0161 end
0162 
0163 %-----------------------------------------------------
0164 % create from SERVER
0165 if Nargs > 0
0166   if ischar(args(1).val)
0167     if strcmp(args(1).val, 'SERVER')
0168       a = aoFromServer(args, VERSION, ALGONAME);
0169       varargout{1} = a;
0170       return
0171     end
0172   end
0173 end
0174 
0175 %-----------------------------------------------------
0176 % create empty AO
0177 if Nargs == 0
0178   a.tag         = -1;
0179   a.name        = 'None';
0180   a.data        = {};
0181   a.hist        = history(ALGONAME, VERSION);
0182   a.provenance  = provenance;
0183   a.comment     = '';
0184   a.mfile       = {};
0185   a.mfilename   = '';
0186   a.mdlfile     = '';
0187   a.mdlfilename = '';
0188   a.version     = VERSION;
0189   a.created     = time;
0190   varargout{1} = class(a, 'ao');
0191 %-----------------------------------------------------
0192 % copy AO, load from file, create from x-data
0193 elseif Nargs == 1              % create ao with data
0194   %%%%%%%%%% Create from XML fragment %%%%%%%%%%%
0195   if isa(args(1).val, 'org.apache.xerces.dom.DeferredElementImpl')
0196     varargout{1} = fromxml(args(1).val);
0197   %%%%%%%%%%% From File %%%%%%%%%%%%%%%%
0198   elseif ischar(args(1).val)
0199 
0200     filename = args(1).val;
0201     [path, name, ext, vers] = fileparts(filename);
0202     switch ext
0203       case '.mat'
0204         a = load(filename);
0205       case '.xml'
0206         a = xmlparse(ao, filename);
0207       case {'.txt', '.dat'}
0208         a = aoFromFilenameAndPlist(args(1).val, plist, VERSION, ALGONAME);
0209       otherwise
0210         error('### Unknown file type.');
0211     end
0212     varargout{1} = a;
0213 
0214   %-----------------------------------------------------
0215   % copy AO
0216   elseif isa(args(1).val, 'ao')
0217     varargout{1} = args(1).val;
0218   %-----------------------------------------------------
0219   % create from struct
0220   elseif isstruct(args(1).val)
0221     astruct = args(1).val;
0222     a.tag  = astruct.tag;
0223     a.name = astruct.name;
0224     data = astruct.data;
0225     if isstruct(data)
0226       if isfield(data, {'t', 'x'})
0227         data = tsdata(data);
0228       elseif isfield(data, {'f', 'xx'})
0229         data = fsdata(data);
0230       elseif isfield(data, {'vals'})
0231         data = cdata(data);
0232       elseif isfield(data, {'x', 'y'})
0233         data = xydata(data);
0234       else
0235         error('### Unknown data type in input structure.');
0236       end
0237     end
0238     a.data = data;
0239     hist   = astruct.hist;
0240     if isstruct(hist)
0241       hist = history(hist);
0242     end
0243     a.hist = hist;
0244     prov = astruct.provenance;
0245     if isstruct(prov)
0246       prov = provenance(prov);
0247     end
0248     a.provenance  = prov;
0249     a.comment     = astruct.comment;
0250     a.mfile       = astruct.mfile;
0251     a.mfilename   = astruct.mfilename;
0252     a.mdlfile     = astruct.mdlfile;
0253     a.mdlfilename = astruct.mdlfilename;
0254     a.version     = astruct.version;
0255     created       = astruct.created;
0256     if isstruct(created)
0257       created = time(created);
0258     end
0259     a.created     = created;
0260     varargout{1}  = class(a, 'ao');
0261 
0262   %-----------------------------------------------------
0263   % create from constant
0264   elseif isnumeric(args(1).val)
0265 
0266     a.tag  = -1;
0267     a.name = 'const';
0268     a.data = cdata(args(1).val);
0269     a.hist = history(ALGONAME, VERSION, plist(param('vals', args(1).val)));
0270 %     a.hist = history(ALGONAME, VERSION, plist(param('fcn', ['[' sprintf('%g ', args(1).val) ']'])));
0271     a.provenance  = provenance;
0272     a.comment     = '';
0273     a.mfile     = {};
0274     a.mfilename = '';
0275     a.mdlfile   = '';
0276     a.mdlfilename = '';
0277     a.version     = VERSION;
0278     a.created     = time;
0279     varargout{1} = class(a, 'ao');
0280 
0281     %-----------------------------------------------------
0282     % create data using plist
0283   elseif isa(args(1).val, 'plist')
0284 
0285     pl       = args(1).val;
0286     filename = find(pl, 'filename');
0287     fcn      = find(pl, 'fcn');
0288     vals     = find(pl, 'vals');
0289     tsfcn    = find(pl, 'tsfcn');
0290     win      = find(pl, 'win');
0291     waveform = find(pl, 'waveform');
0292 
0293     if ~isempty(filename)
0294       % do filename constructor
0295       varargout{1} = aoFromFilenameAndPlist(filename, pl, VERSION, ALGONAME);
0296 
0297     elseif ~isempty(fcn)
0298       % do function constructor
0299       varargout{1} = aoFromFcn(pl, VERSION, ALGONAME);
0300 
0301     elseif ~isempty(vals)
0302       % do vals constructor
0303       varargout{1} = aoFromVals(vals, VERSION, ALGONAME);
0304 
0305     elseif ~isempty(tsfcn)
0306       % do tsfcn constructor
0307       varargout{1} = aoFromTSfcn(pl, VERSION, ALGONAME);
0308 
0309     elseif ~isempty(win)
0310       % do win constructor
0311       varargout{1} = aoFromSpecWin(win, VERSION, ALGONAME);
0312 
0313     elseif ~isempty(waveform)
0314       % do waveform constructor
0315       varargout{1} = aoFromWaveform(pl, VERSION, ALGONAME);
0316 
0317     else
0318       error('### Unknown AO constructor method.');
0319     end
0320 
0321   %-----------------------------------------------------
0322   % create from spectral window
0323   elseif isa(args(1).val, 'specwin')
0324     varargout{1} = aoFromSpecWin(args(1).val, VERSION, ALGONAME);
0325   %-----------------------------------------------------
0326   % create from x-data
0327   else
0328     data        = args(1).val;
0329     a.tag       = -1;
0330     a.name      = 'None';
0331     a.data      = data;
0332     a.hist      = history(ALGONAME, VERSION);
0333     a.provenance  = provenance;
0334     a.comment     = '';
0335     a.mfile     = {};
0336     a.mfilename = '';
0337     a.mdlfile   = '';
0338     a.mdlfilename = '';
0339     a.version     = VERSION;
0340     a.created     = time;
0341     varargout{1} = class(a, 'ao');
0342     if ~isa(a.data, 'tsdata') &&...
0343        ~isa(a.data, 'fsdata') &&...
0344        ~isa(a.data, 'cdata')  &&...
0345        ~isa(a.data, 'xydata')
0346       error('### unknown data object.')
0347     end
0348   end
0349 %-----------------------------------------------------
0350 %   data, hist
0351 %  'file_name.txt', pl
0352 elseif Nargs == 2
0353 
0354   %%%%%%%%%%% Database
0355   if isa(varargin{1}, 'database')
0356     varargout{1} = retrieve(varargin{1}, varargin{2:end});
0357 
0358   %%%%%%%%%%% 'file_name.txt', pl
0359   elseif ischar(args(1).val) && isa(args(2).val, 'plist')
0360 
0361     ao_out = aoFromFilenameAndPlist(args(1).val, args(2).val, VERSION, ALGONAME);
0362 
0363     if nargout == 1
0364       varargout{1} = ao_out;
0365     elseif nargout == length(ao_out)
0366       for ii = 1:length(ao_out)
0367         varargout{ii} = ao_out(ii);
0368       end
0369     else
0370       warning ('### Too few output variables --> useing only the first.');
0371       varargout{1} = ao_out;
0372     end
0373 
0374   % data, hist
0375   else
0376 
0377     a.tag       = -1;
0378     a.name      = 'None';
0379     a.data      = args(1).val;
0380     a.hist      = args(2).val; %history(ALGONAME, VERSION, [], varargin{2});
0381     a.provenance  = provenance;
0382     a.comment     = '';
0383     a.mfile     = {};
0384     a.mfilename = '';
0385     a.mdlfile   = '';
0386     a.mdlfilename = '';
0387     a.version     = VERSION;
0388     a.created     = time;
0389     varargout{1} = class(a, 'ao');
0390     if ~isa(a.data, 'tsdata') &&...
0391         ~isa(a.data, 'fsdata') &&...
0392         ~isa(a.data, 'cdata')  &&...
0393         ~isa(a.data, 'xydata')
0394       error('### unknown data object.')
0395     end
0396     if ~isa(a.hist, 'history')
0397       error('### unknown history object.')
0398     end
0399 
0400   end
0401 
0402 
0403 %-----------------------------------------------------
0404 %  full constructor - all fields
0405 elseif Nargs == 9
0406 
0407   a.tag         = args(1).val;
0408   a.name        = args(2).val;
0409   a.data        = args(3).val;
0410   a.hist        = args(4).val;
0411   a.provenance  = args(5).val;
0412   a.comment     = args(6).val;
0413   a.mfile       = args(7).val;
0414   a.mfilename   = args(8).val;
0415   a.mdlfile     = args(9).val;
0416   a.mdlfilename = args(10).val;
0417   a.version     = VERSION;
0418   a.created     = time;
0419   varargout{1} = class(a, 'ao');
0420 
0421 else
0422   error('### Unknown number of constructor arguments.');
0423 end
0424 
0425 %--------------------------------------------------------------------------
0426 % construct an ao from a value set
0427 %
0428 function a = aoFromVals(vals, VERSION, ALGONAME)
0429 
0430 % Make a cdata object
0431 ts = cdata(plist(param('vals', vals)));
0432 ts = set(ts, 'name', 'Data');
0433 
0434 % Make an analysis object
0435 a.tag  = -1;
0436 a.name = 'Data';
0437 a.data = ts;
0438 a.hist = history(ALGONAME, VERSION, plist(param('vals', vals)));
0439 a.provenance  = provenance;
0440 a.comment     = '';
0441 a.mfile     = {};
0442 a.mfilename = '';
0443 a.mdlfile   = '';
0444 a.mdlfilename = '';
0445 a.version     = VERSION;
0446 a.created     = time;
0447 a = class(a, 'ao');
0448 
0449 
0450 
0451 %--------------------------------------------------------------------------
0452 % construct an ao from a waveform
0453 %
0454 function a = aoFromWaveform(pl, VERSION, ALGONAME)
0455 
0456 waveform = find(pl, 'waveform');
0457 switch waveform
0458   %------------ Sine Wave
0459   case 'sine wave'
0460     freq = find(pl, 'f');
0461     phi  = find(pl, 'phi');
0462     tsfcn = sprintf('sin(2*pi*%g*t + %g*pi/180)', freq, phi);
0463     %------------ Noise
0464   case 'noise'
0465     ntype = find(pl, 'type');
0466     switch ntype
0467       case 'Normal'
0468         tsfcn = 'randn(size(t))';
0469       case 'Uniform'
0470         tsfcn = 'rand(size(t))';
0471     end
0472     %------------ Chirp
0473   case 'chirp'
0474     f0  = find(pl, 'f0');
0475     fe  = find(pl, 'f1');
0476     te  = find(pl, 't1');
0477     tsfcn = sprintf('chirp(t,%g,%g,%g)', f0, fe, te);
0478     %------------ Gaussian pulse
0479   case 'Gaussian pulse'
0480     fc  = find(pl, 'f0');
0481     bw  = find(pl, 'bw');
0482     tsfcn = sprintf('gauspuls(t,%g,%g)', fc, bw);
0483   case 'Square wave'
0484     freq = find(pl, 'f');
0485     duty = find(pl, 'duty');
0486     tsfcn = sprintf('square(2*pi*%g*t,%g)', freq, duty);
0487   case 'Sawtooth'
0488     freq  = find(pl, 'f');
0489     width = find(pl, 'width');
0490     tsfcn = sprintf('sawtooth(2*pi*%g*t,%g)', freq, width);
0491 end
0492 
0493 nsecs  = find(pl, 'nsecs');
0494 fs     = find(pl, 'fs');
0495 
0496 % construct tsdata
0497 t = linspace(0, nsecs-1/fs, nsecs*fs);
0498 % make y data
0499 eval(['y=' tsfcn ';']);
0500 
0501 ts = tsdata(t,y);
0502 ts = set(ts, 'name', tsfcn);
0503 ts = set(ts, 'xunits', 's');
0504 ts = set(ts, 'yunits', 'V');
0505 
0506 % Make an analysis object
0507 a.tag  = -1;
0508 a.name = waveform;
0509 a.data = ts;
0510 a.hist = history(ALGONAME, VERSION, pl);
0511 a.provenance  = provenance;
0512 a.comment     = '';
0513 a.mfile     = {};
0514 a.mfilename = '';
0515 a.mdlfile   = '';
0516 a.mdlfilename = '';
0517 a.version     = VERSION;
0518 a.created     = time;
0519 a = class(a, 'ao');
0520 
0521 
0522 
0523 %--------------------------------------------------------------------------
0524 % construct an ao from a ts-function string
0525 %
0526 function a = aoFromTSfcn(pl, VERSION, ALGONAME)
0527 
0528 nsecs       = find(pl, 'nsecs');
0529 fs          = find(pl, 'fs');
0530 fcn         = find(pl, 'tsfcn');
0531 randn_state = find(pl, 'rand_state');
0532 
0533 % construct tsdata
0534 t = linspace(0, nsecs-1/fs, nsecs*fs);
0535 % make y data
0536 
0537 % If the randn state is in the parameter list then set the randn function to
0538 % this sate
0539 if ~isempty(randn_state)
0540   randn('state',randn_state);
0541 else % Store the state of the random function in the parameter list
0542   randn_state = randn('state');
0543   pl = append(pl , 'rand_state', randn_state);
0544 end
0545 
0546 y = eval([fcn ';']);
0547 
0548 ts = tsdata(t,y);
0549 ts = set(ts, 'name', fcn);
0550 ts = set(ts, 'xunits', 's');
0551 ts = set(ts, 'yunits', 'V');
0552 
0553 % Make an analysis object
0554 a.tag  = -1;
0555 a.name = 'TSfcn';
0556 a.data = ts;
0557 a.hist = history(ALGONAME, VERSION, pl);
0558 a.provenance  = provenance;
0559 a.comment     = '';
0560 a.mfile     = {};
0561 a.mfilename = '';
0562 a.mdlfile   = '';
0563 a.mdlfilename = '';
0564 a.version     = VERSION;
0565 a.created     = time;
0566 a = class(a, 'ao');
0567 
0568 %--------------------------------------------------------------------------
0569 % construct an ao from a function string
0570 %
0571 function a = aoFromFcn(pl, VERSION, ALGONAME)
0572 
0573 fcn = find(pl, 'fcn');
0574 
0575 % Make a cdata object
0576 ts = cdata(plist(param('fcn', fcn)));
0577 ts = set(ts, 'name', fcn);
0578 
0579 % Make an analysis object
0580 a.tag  = -1;
0581 a.name = fcn;
0582 a.data = ts;
0583 a.hist = history(ALGONAME, VERSION, pl);
0584 a.provenance  = provenance;
0585 a.comment     = '';
0586 a.mfile     = {};
0587 a.mfilename = '';
0588 a.mdlfile   = '';
0589 a.mdlfilename = '';
0590 a.version     = VERSION;
0591 a.created     = time;
0592 a = class(a, 'ao');
0593 
0594 %--------------------------------------------------------------------------
0595 % construct an ao from filename
0596 %
0597 function a = aoFromFilename(filename, VERSION, ALGONAME)
0598 
0599 [path,fname,ext,versn] = fileparts(filename);
0600 switch ext
0601   case {'.txt','.dat'}
0602     disp(['  + creating AO from text file ' filename]);
0603 
0604     in = load(filename);
0605     t  = in(:,1);
0606     x  = in(:,2);
0607 
0608     % Make a tsdata object
0609     ts = tsdata(t,x);
0610     ts = set(ts, 'name', fname);
0611     ts = set(ts, 'xunits', 's');
0612     ts = set(ts, 'yunits', 'V');
0613 
0614     % Make an analysis object
0615     a.tag  = -1;
0616     a.name = fname;
0617     a.data = ts;
0618     a.hist = history(ALGONAME, VERSION, plist([param('filename', [fname ext]) param('filepath', path)]));
0619     a.provenance  = provenance;
0620     a.comment     = '';
0621     a.mfile       = {};
0622     a.mfilename   = '';
0623     a.mdlfile     = '';
0624     a.mdlfilename = '';
0625     a.version     = VERSION;
0626     a.created     = time;
0627     a = class(a, 'ao');
0628 
0629   case '.mat'
0630 %     disp('??? I do not work yet. Please code me up.');
0631 
0632     in = load(filename);
0633     fnames = fieldnames(in);
0634     eval(sprintf('a = in.%s;', fnames{1}));
0635 
0636   case '.xml'
0637 
0638     [tag, name, prov, comment, mfile, mfname, mdlfile, mdlfname, hist, data] = xml_read(filename);
0639     a.tag  = tag;
0640     a.name = name;
0641     a.data = data;
0642 %     a.hist = hist;
0643     a.hist = history(ALGONAME, VERSION, plist([param('filename', [fname ext]) param('filepath', path)]), hist);
0644     a.provenance  = prov;
0645     a.comment     = comment;
0646     a.mfile       = mfile;
0647     a.mfilename   = mfname;
0648     a.mdlfile     = mdlfile;
0649     a.mdlfilename = mdlfname;
0650     a.version     = VERSION;
0651     a.created     = time;
0652     a = class(a, 'ao');
0653 
0654   otherwise
0655     error('### unknown file type.');
0656 end
0657 
0658 %--------------------------------------------------------------------------
0659 % construct an ao from filename AND parameter list
0660 %
0661 function a = aoFromFilenameAndPlist(file_name, pl, VERSION, ALGONAME)
0662 
0663   a = [];
0664 
0665   disp(['  + creating AO(s) from text file: ' file_name]);
0666 
0667   [pathstr, f_name, ext] = fileparts(file_name);
0668 
0669   %%%%%%%%%%   Define default parameter list   %%%%%%%%%%
0670   pl_default = plist('columns',      [1 2],    ...
0671                      'num_columns',   10,      ...
0672                      'type',         'tsdata', ...
0673                      'use_fs',       '',       ...
0674                      'comment_char', '%');
0675   pl = combine(pl, pl_default);
0676 
0677   pl = append(pl, param('filename', [f_name ext]));
0678   pl = append(pl, param('filepath', pathstr));
0679 
0680   data_type    = find (pl, 'type');
0681   columns      = find (pl, 'columns');
0682   num_columns  = find (pl, 'num_columns');
0683   comment_char = find (pl, 'comment_char');
0684   use_fs       = find (pl, 'use_fs');
0685 
0686   %%%%%%%%%%   read file   %%%%%%%%%%
0687   [fid,msg] = fopen (file_name, 'r');
0688   if (fid < 0)
0689     error ('### can not open file: %s \n\n### error msg:',file_name, msg);
0690   end
0691 
0692   %%%%%%%%%% create scan format: '%f %f %f %f %f'   %%%%%%%%%%
0693   scan_format = [];
0694   for ii=1:num_columns
0695     scan_format = [scan_format '%f '];
0696   end
0697   scan_format = scan_format(1:end-1); % remove the last whitespace
0698 
0699   %%%%%%%%%%   scan the file   %%%%%%%%%%
0700   raw_data = textscan( fid, scan_format,             ...
0701                       'commentStyle',  comment_char, ...
0702                       'CollectOutput', 1);
0703   f_data = raw_data{1};
0704 
0705   if isempty(f_data)
0706     error([char(10) '### There are no data. ' ...
0707                     'Did you use the right comment character?'            char(10) ...
0708                     '### The current comment character is: ' comment_char char(10) ...
0709                     '### Use a parameter list with the parameter:'        char(10) ...
0710                     '### plist(''comment_char'', ''%'')']);
0711   end
0712 
0713   fclose(fid);
0714 
0715   %%%%%%%%%%   Create for each column pair the data object   %%%%%%%%%%
0716   if isempty(use_fs)
0717 
0718     %%%%%%%%%%   The numbers in columns must be straight   %%%%%%%%%%
0719     if mod(length(columns),2) ~= 0
0720       error('### the numbers in columns must be straight');
0721     end
0722 
0723     for lauf = 1:length(columns)/2
0724 
0725       data_x_axes = f_data(:, columns(lauf*2-1));
0726       data_y_axes = f_data(:, columns(lauf*2));
0727 
0728       %% create data object corresponding to the parameter list
0729       ao_data = [];
0730       switch data_type
0731         case 'tsdata'
0732           ao_data = tsdata( data_x_axes, data_y_axes);
0733         case 'fsdata'
0734           ao_data = fsdata( data_x_axes, data_y_axes);
0735         case 'cdata'
0736           error ('### please code me up')
0737         case 'xydata'
0738           ao_data = xydata( data_x_axes, data_y_axes);
0739         otherwise
0740           error('### unknown data type ''%s''', data_type);
0741       end
0742       ao_data.name = sprintf('f_name_%02d', lauf);
0743 
0744       aa      = [];
0745       aa.tag  = -1;
0746       aa.name = sprintf('f_name_%02d', lauf);
0747       aa.data = ao_data;
0748       aa.hist = history(ALGONAME, VERSION, pl);
0749       aa.provenance  = provenance;
0750 
0751       %% Set thecomment fron the parameter list or from the file
0752       comment_pl = find(pl, 'comment');
0753       if ~isempty(comment_pl)
0754         aa.comment = comment_pl;
0755       else
0756         aa.comment     = '';
0757       end
0758 
0759       aa.mfile     = {};
0760       aa.mfilename = '';
0761       aa.mdlfile   = '';
0762       aa.mdlfilename = '';
0763       aa.version     = VERSION;
0764       aa.created     = time;
0765       aa = class(aa, 'ao');
0766 
0767       a = [a aa];
0768 
0769     end
0770 
0771   %%%%%%%%%%   Create for each column AND fs a data object   %%%%%%%%%%
0772   else % isempty(use_fs)
0773 
0774     for lauf = 1:length(columns)
0775 
0776       data_y_axes = f_data(:, columns(lauf));
0777 
0778       %% create data object corresponding to the parameter list
0779       ao_data = [];
0780       switch data_type
0781         case 'tsdata'
0782           ao_data = tsdata(data_y_axes, use_fs);
0783         case 'fsdata'
0784           ao_data = fsdata(data_y_axes, use_fs);
0785         case 'cdata'
0786           error ('### please code me up')
0787         case 'xydata'
0788           error ('### please code me up')
0789         otherwise
0790           error('### unknown data type ''%s''', data_type);
0791       end
0792       ao_data.name = sprintf('f_name_%02d', lauf);
0793 
0794       aa      = [];
0795       aa.tag  = -1;
0796       aa.name = sprintf('f_name_%02d', lauf);
0797       aa.data = ao_data;
0798       aa.hist = history(ALGONAME, VERSION, pl);
0799       aa.provenance  = provenance;
0800 
0801       %% Set thecomment fron the parameter list or from the file
0802       comment_pl = find(pl, 'comment');
0803       if ~isempty(comment_pl)
0804         aa.comment = comment_pl;
0805       else
0806         aa.comment     = '';
0807       end
0808 
0809       aa.mfile       = {};
0810       aa.mfilename   = '';
0811       aa.mdlfile     = '';
0812       aa.mdlfilename = '';
0813       aa.version     = VERSION;
0814       aa.created     = time;
0815       aa = class(aa, 'ao');
0816 
0817       a = [a aa];
0818 
0819     end
0820 
0821   end
0822 
0823   %%%%%%%%%%   set fields of the data object from the parameter list   %%%%%%%%%%
0824   for ii = 1:length(a)
0825     fields = fieldnames(a(ii).data);
0826 
0827     for jj = 1:length(pl.params)
0828       parameter = pl.params(jj);
0829 
0830       if ismember(parameter.key, fields)
0831 
0832         if iscell(parameter.val)
0833           if length(parameter.val) > 1
0834             if length(parameter.val) ~= length(a)
0835               warning([sprintf('The values of the key ''%s'' ', parameter.key) ...
0836                                'have not the same length as the lenthg of '    ...
0837                                'the output. Using the first value!']);
0838               a(ii).data.(parameter.key) = parameter.val{1};
0839             else
0840               a(ii).data.(parameter.key) = parameter.val{ii};
0841             end
0842           else
0843             a(ii).data.(parameter.key) = parameter.val{1};
0844           end
0845         else
0846           a(ii).data.(parameter.key) = parameter.val;
0847         end
0848 
0849       end % is parameter key member of the data object
0850     end % for-loop over all parameter
0851   end % for-loop over all ao's
0852 
0853 
0854 %--------------------------------------------------------------------------
0855 % construct an ao from a Spectral window
0856 %
0857 function a = aoFromSpecWin(win, VERSION, ALGONAME)
0858 
0859 % Make a cdata object
0860 ts = cdata(win.win);
0861 ts = set(ts, 'name', win.name);
0862 
0863 % Make an analysis object
0864 a.tag  = -1;
0865 a.name = win.name;
0866 a.data = ts;
0867 a.hist = history(ALGONAME, VERSION, plist(param('win', win)));
0868 a.provenance  = provenance;
0869 a.comment     = '';
0870 a.mfile       = {};
0871 a.mfilename   = '';
0872 a.mdlfile     = '';
0873 a.mdlfilename = '';
0874 a.version     = VERSION;
0875 a.created     = time;
0876 a = class(a, 'ao');
0877 
0878 
0879 
0880 %--------------------------------------------------------------------------
0881 % construct an ao from server
0882 %
0883 function bs = aoFromServer(args, VERSION, ALGONAME);
0884 
0885 % retrieve ao from server
0886 bs = retrieve(args(2).val, [args(3:end).val]);
0887 
0888 % END

Generated on Thu 01-Nov-2007 09:42:34 by m2html © 2003