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'
                             'columns' = [1 2 1 4]             -> two ao's
                                          default = [1 2]
                                          Each pair represented the x- and y-axes
                             '...'        every property of the class in 'type'
                                          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([param('colums', [1 2 1 3])
                                         param('name',   {'name1' 'name2'})
                                         param('xunits', 'sec')
                                         param('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(1:20); % get a matrix of data values [t x];
   [x,y] = a.data(1:20); % get x,y data from data object.


 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 %                             'columns' = [1 2 1 4]             -> two ao's
0032 %                                          default = [1 2]
0033 %                                          Each pair represented the x- and y-axes
0034 %                             '...'        every property of the class in 'type'
0035 %                                          e.g. 'name'
0036 %                             If the constructor creates multiple ao's it is
0037 %                             possible to give each data class its own e.g.
0038 %                             'name'. In this case the parameter list with the
0039 %                             key 'name' must have cell of the different values
0040 %                             as the name of the different data objects. e.g.
0041 %                             pl = plist([param('colums', [1 2 1 3])
0042 %                                         param('name',   {'name1' 'name2'})
0043 %                                         param('xunits', 'sec')
0044 %                                         param('yunits', {'V' 'Hz'})]);
0045 %                             This parameter list creates two ao's with tsdata.
0046 %       a = ao(plist)       - creates an analysis object with by reading
0047 %                             the file specified by the 'filename'
0048 %                             parameter in the plist.
0049 %       a = ao(data)        - creates an analysis object with a data
0050 %                             object. Data object can be one of tsdata,
0051 %                             fsdata.
0052 %       a = ao(data, hist)  - creates an analysis object with a data
0053 %                             object and a history object
0054 %
0055 %       a = ao(specwin)     - creates an analysis object from a specwin
0056 %                             object
0057 %
0058 % Parameters for plist constructor:
0059 %
0060 %   'filename' - construct an AO from a filename.
0061 %                Example: plist(param('filename', 'a1.xml'))
0062 %
0063 %   'fcn'      - construct an AO from some valid MATLAB function.
0064 %                Example: plist(param('fcn', 'randn(100)'))
0065 %
0066 %   'vals'     - construct an AO from a set of values.
0067 %                Example: plist(param('vals', [1 2 3]))
0068 %
0069 %   'tsfcn'    - construct an AO from a function of time. You need to also
0070 %                specify parameters 'fs' and 'nsecs' for this call.
0071 %                Example:
0072 %                  plist([param('fs', 10) param('nsecs', 10) param('tsfcn',
0073 %                  'sin(2*pi*1.4*t) + 0.1*randn(size(t))')])
0074 %
0075 %   'win'      - construct an AO from a specwin window function. Tjis
0076 %                creates a cdata type AO containing the window values.
0077 %                Example: plist(param('win', specwin('Hannning', 100)))
0078 %
0079 %   'waveform' - construct an AO from a waveform description. Here you need
0080 %                to specify additional parameters 'fs' and 'nsecs', and also,
0081 %                for the following waveform types:
0082 %                'sine wave'      - 'f', 'phi'
0083 %                'noise'          - 'type' (can be 'Normal' or 'Uniform')
0084 %                'chirp'          - 'f0', 'f1', 't1'      (help chirp)
0085 %                'Gaussian pulse' - 'f0', 'bw'            (help gauspuls)
0086 %                'Square wave'    - 'f', 'duty'           (help square)
0087 %                'Sawtooth'       - 'f', 'width'          (help sawtooth)
0088 %
0089 %     Indexing:
0090 %       b = a(1) % where a is an array of analysis objects
0091 %       d = a.data; % get the data object
0092 %       h = a.hist; % get the history object
0093 %       d = a.data(1:20); % get a matrix of data values [t x];
0094 %   [x,y] = a.data(1:20); % get x,y data from data object.
0095 %
0096 %
0097 % See also tsdata, fsdata, xydata, cdata
0098 %
0099 % M Hewitson 30-01-07
0100 %
0101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0102 
0103 %       a = ao('object.mat') - creates a new analysis object by loading the
0104 %                             analysis object from disk.
0105 
0106 ALGONAME = mfilename;
0107 VERSION  = '$Id: ao.html,v 1.2 2007/07/10 05:37:08 hewitson Exp $';
0108 
0109 % process input arguments
0110 args = [];
0111 k = 0;
0112 pls = [];
0113 for j=1:nargin
0114   if ~isempty(varargin{j})
0115     k = k + 1;
0116     if isa(varargin{j}, 'plist')
0117       pls = [pls varargin{j}];
0118     else
0119       args(k).val = varargin{j};
0120       args(k).n   = j;
0121     end
0122   end
0123 end
0124 
0125 % We could have multiple input plist objects. Combine them here.
0126 if isa(pls, 'plist')
0127   pl = combine(pls);
0128 else
0129   pl = [];
0130 end
0131 
0132 Nargs = length(args);
0133 if ~isempty(pl)
0134   args(Nargs+1).val = pl;
0135   args(Nargs+1).n   = j+1;
0136   Nargs = length(args);
0137 end
0138 
0139 %-----------------------------------------------------
0140 % create from SERVER
0141 if Nargs > 0
0142   if ischar(args(1).val)
0143     if strcmp(args(1).val, 'SERVER')
0144       a = aoFromServer(args, VERSION, ALGONAME);
0145       return
0146     end
0147   end
0148 end
0149 
0150 %-----------------------------------------------------
0151 % create empty AO
0152 if Nargs == 0
0153   a.tag         = -1;
0154   a.name        = 'None';
0155   a.data        = {};
0156   a.hist        = history(ALGONAME, VERSION);
0157   a.provenance  = provenance;
0158   a.comment     = '';
0159   a.mfile       = {};
0160   a.mfilename   = '';
0161   a.mdlfile     = '';
0162   a.mdlfilename = '';
0163   varargout{1} = class(a, 'ao');
0164 %-----------------------------------------------------
0165 % copy AO, load from file, create from x-data
0166 elseif Nargs == 1              % create ao with data
0167   %-----------------------------------------------------
0168   % copy AO
0169   if isa(args(1).val, 'ao')
0170     varargout{1} = args(1).val;
0171   %-----------------------------------------------------
0172   % create from struct
0173   elseif isstruct(args(1).val)
0174     astruct = args(1).val;
0175     a.tag  = astruct.tag;
0176     a.name = astruct.name;
0177     data = astruct.data;
0178     if isstruct(data)
0179       if isfield(data, {'t', 'x'})
0180         data = tsdata(data);
0181       elseif isfield(data, {'f', 'xx'})
0182         data = fsdata(data);
0183       elseif isfield(data, {'vals'})
0184         data = cdata(data);
0185       elseif isfield(data, {'x', 'y'})
0186         data = xydata(data);
0187       else
0188         error('### Unknown data type in input structure.');
0189       end
0190     end
0191     a.data = data;
0192     hist   = astruct.hist;
0193     if isstruct(hist)
0194       hist = history(hist);
0195     end
0196     a.hist = hist;
0197     prov = astruct.provenance;
0198     if isstruct(prov)
0199       prov = provenance(prov);
0200     end
0201     a.provenance  = prov;
0202     a.comment     = astruct.comment;
0203     a.mfile       = astruct.mfile;
0204     a.mfilename   = astruct.mfilename;
0205     a.mdlfile     = astruct.mdlfile;
0206     a.mdlfilename = astruct.mdlfilename;
0207     varargout{1} = class(a, 'ao');
0208 
0209   %-----------------------------------------------------
0210   % create from constant
0211   elseif isnumeric(args(1).val)
0212 
0213     a.tag  = -1;
0214     a.name = 'const';
0215     a.data = cdata(args(1).val);
0216     a.hist = history(ALGONAME, VERSION, plist(param('vals', args(1).val)));
0217 %     a.hist = history(ALGONAME, VERSION, plist(param('fcn', ['[' sprintf('%g ', args(1).val) ']'])));
0218     a.provenance  = provenance;
0219     a.comment     = '';
0220     a.mfile     = {};
0221     a.mfilename = '';
0222     a.mdlfile   = '';
0223     a.mdlfilename = '';
0224     varargout{1} = class(a, 'ao');
0225 
0226     %-----------------------------------------------------
0227     % create data using plist
0228   elseif isa(args(1).val, 'plist')
0229 
0230     pl       = args(1).val;
0231     filename = find(pl, 'filename');
0232     fcn      = find(pl, 'fcn');
0233     vals     = find(pl, 'vals');
0234     tsfcn    = find(pl, 'tsfcn');
0235     win      = find(pl, 'win');
0236     waveform = find(pl, 'waveform');
0237 
0238     if ~isempty(filename)
0239       % do filename constructor
0240       varargout{1} = aoFromFilename(filename, VERSION, ALGONAME);
0241 
0242     elseif ~isempty(fcn)
0243       % do function constructor
0244       varargout{1} = aoFromFcn(pl, VERSION, ALGONAME);
0245 
0246     elseif ~isempty(vals)
0247       % do vals constructor
0248       varargout{1} = aoFromVals(vals, VERSION, ALGONAME);
0249 
0250     elseif ~isempty(tsfcn)
0251       % do tsfcn constructor
0252       varargout{1} = aoFromTSfcn(pl, VERSION, ALGONAME);
0253 
0254     elseif ~isempty(win)
0255       % do win constructor
0256       varargout{1} = aoFromSpecWin(win, VERSION, ALGONAME);
0257 
0258     elseif ~isempty(waveform)
0259       % do waveform constructor
0260       varargout{1} = aoFromWaveform(pl, VERSION, ALGONAME);
0261 
0262     else
0263       error('### Unknown AO constructor method.');
0264     end
0265 
0266   %-----------------------------------------------------
0267   % create from spectral window
0268   elseif isa(args(1).val, 'specwin')
0269     varargout{1} = aoFromSpecWin(args(1).val, VERSION, ALGONAME);
0270   %-----------------------------------------------------
0271   % create from filename
0272   elseif ischar(args(1).val)
0273     varargout{1} = aoFromFilename(args(1).val, VERSION, ALGONAME);
0274   %-----------------------------------------------------
0275   % create from x-data
0276   else
0277     data        = args(1).val;
0278     a.tag       = -1;
0279     a.name      = 'None';
0280     a.data      = data;
0281     dinfo       = whos('data');
0282     a.hist      = history(ALGONAME, VERSION, plist([param('input', inputname(1)) param('type', ['AO/' dinfo.class])]));
0283     a.provenance  = provenance;
0284     a.comment     = '';
0285     a.mfile     = {};
0286     a.mfilename = '';
0287     a.mdlfile   = '';
0288     a.mdlfilename = '';
0289     varargout{1} = class(a, 'ao');
0290     if ~isa(a.data, 'tsdata') &&...
0291        ~isa(a.data, 'fsdata') &&...
0292        ~isa(a.data, 'cdata')  &&...
0293        ~isa(a.data, 'xydata')
0294       error('### unknown data object.')
0295     end
0296   end
0297 %-----------------------------------------------------
0298 %   data, hist
0299 %  'file_name.txt', pl
0300 elseif Nargs == 2
0301   % 'file_name.txt', pl
0302   if ischar(args(1).val) && isa(args(2).val, 'plist')
0303 
0304     ao_out = aoFromFilenameAndPlist(args(1).val, args(2).val, VERSION, ALGONAME);
0305 
0306     if nargout == 1
0307       varargout{1} = ao_out;
0308     elseif nargout == length(ao_out)
0309       for ii = 1:length(ao_out)
0310         varargout{ii} = ao_out(ii);
0311       end
0312     else
0313       warning ('### Too few output variables --> useing only the first.');
0314       varargout{1} = ao_out;
0315     end
0316 
0317   % data, hist
0318   else
0319 
0320     a.tag       = -1;
0321     a.name      = 'None';
0322     a.data      = args(1).val;
0323     a.hist      = args(2).val; %history(ALGONAME, VERSION, [], varargin{2});
0324     a.provenance  = provenance;
0325     a.comment     = '';
0326     a.mfile     = {};
0327     a.mfilename = '';
0328     a.mdlfile   = '';
0329     a.mdlfilename = '';
0330     varargout{1} = class(a, 'ao');
0331     if ~isa(a.data, 'tsdata') &&...
0332         ~isa(a.data, 'fsdata') &&...
0333         ~isa(a.data, 'cdata')  &&...
0334         ~isa(a.data, 'xydata')
0335       error('### unknown data object.')
0336     end
0337     if ~isa(a.hist, 'history')
0338       error('### unknown history object.')
0339     end
0340 
0341   end
0342 
0343 
0344 %-----------------------------------------------------
0345 %  full constructor - all fields
0346 elseif Nargs == 9
0347 
0348   a.tag         = args(1).val;
0349   a.name        = args(2).val;
0350   a.data        = args(3).val;
0351   a.hist        = args(4).val;
0352   a.provenance  = args(5).val;
0353   a.comment     = args(6).val;
0354   a.mfile       = args(7).val;
0355   a.mfilename   = args(8).val;
0356   a.mdlfile     = args(9).val;
0357   a.mdlfilename = args(10).val;
0358   varargout{1} = class(a, 'ao');
0359 
0360 else
0361   error('### Unknown number of constructor arguments.');
0362 end
0363 
0364 %--------------------------------------------------------------------------
0365 % construct an ao from a value set
0366 %
0367 function a = aoFromVals(vals, VERSION, ALGONAME)
0368 
0369 % Make a cdata object
0370 ts = cdata(plist(param('vals', vals)));
0371 ts = set(ts, 'name', 'Data');
0372 
0373 % Make an analysis object
0374 a.tag  = -1;
0375 a.name = 'Data';
0376 a.data = ts;
0377 a.hist = history(ALGONAME, VERSION, plist(param('vals', vals)));
0378 a.provenance  = provenance;
0379 a.comment     = '';
0380 a.mfile     = {};
0381 a.mfilename = '';
0382 a.mdlfile   = '';
0383 a.mdlfilename = '';
0384 a = class(a, 'ao');
0385 
0386 
0387 
0388 %--------------------------------------------------------------------------
0389 % construct an ao from a waveform
0390 %
0391 function a = aoFromWaveform(pl, VERSION, ALGONAME)
0392 
0393 waveform = find(pl, 'waveform');
0394 switch waveform
0395   %------------ Sine Wave
0396   case 'sine wave'
0397     freq = find(pl, 'f');
0398     phi  = find(pl, 'phi');
0399     tsfcn = sprintf('sin(2*pi*%g*t + %g*pi/180)', freq, phi);
0400     %------------ Noise
0401   case 'noise'
0402     ntype = find(pl, 'type');
0403     switch ntype
0404       case 'Normal'
0405         tsfcn = 'randn(size(t))';
0406       case 'Uniform'
0407         tsfcn = 'rand(size(t))';
0408     end
0409     %------------ Chirp
0410   case 'chirp'
0411     f0  = find(pl, 'f0');
0412     fe  = find(pl, 'f1');
0413     te  = find(pl, 't1');
0414     tsfcn = sprintf('chirp(t,%g,%g,%g)', f0, fe, te);
0415     %------------ Gaussian pulse
0416   case 'Gaussian pulse'
0417     fc  = find(pl, 'f0');
0418     bw  = find(pl, 'bw');
0419     tsfcn = sprintf('gauspuls(t,%g,%g)', fc, bw);
0420   case 'Square wave'
0421     freq = find(pl, 'f');
0422     duty = find(pl, 'duty');
0423     tsfcn = sprintf('square(2*pi*%g*t,%g)', freq, duty);
0424   case 'Sawtooth'
0425     freq  = find(pl, 'f');
0426     width = find(pl, 'width');
0427     tsfcn = sprintf('sawtooth(2*pi*%g*t,%g)', freq, width);
0428 end
0429 
0430 nsecs  = find(pl, 'nsecs');
0431 fs     = find(pl, 'fs');
0432 
0433 % construct tsdata
0434 t = linspace(0, nsecs-1/fs, nsecs*fs);
0435 % make y data
0436 eval(['y=' tsfcn ';']);
0437 
0438 ts = tsdata(t,y);
0439 ts = set(ts, 'name', tsfcn);
0440 ts = set(ts, 'xunits', 's');
0441 ts = set(ts, 'yunits', 'V');
0442 
0443 % Make an analysis object
0444 a.tag  = -1;
0445 a.name = waveform;
0446 a.data = ts;
0447 a.hist = history(ALGONAME, VERSION, pl);
0448 a.provenance  = provenance;
0449 a.comment     = '';
0450 a.mfile     = {};
0451 a.mfilename = '';
0452 a.mdlfile   = '';
0453 a.mdlfilename = '';
0454 a = class(a, 'ao');
0455 
0456 
0457 
0458 %--------------------------------------------------------------------------
0459 % construct an ao from a ts-function string
0460 %
0461 function a = aoFromTSfcn(pl, VERSION, ALGONAME)
0462 
0463 nsecs  = find(pl, 'nsecs');
0464 fs     = find(pl, 'fs');
0465 fcn    = find(pl, 'tsfcn');
0466 
0467 % construct tsdata
0468 t = linspace(0, nsecs-1/fs, nsecs*fs);
0469 % make y data
0470 y = eval([fcn ';']);
0471 
0472 ts = tsdata(t,y);
0473 ts = set(ts, 'name', fcn);
0474 ts = set(ts, 'xunits', 's');
0475 ts = set(ts, 'yunits', 'V');
0476 
0477 % Make an analysis object
0478 a.tag  = -1;
0479 a.name = 'TSfcn';
0480 a.data = ts;
0481 a.hist = history(ALGONAME, VERSION, pl);
0482 a.provenance  = provenance;
0483 a.comment     = '';
0484 a.mfile     = {};
0485 a.mfilename = '';
0486 a.mdlfile   = '';
0487 a.mdlfilename = '';
0488 a = class(a, 'ao');
0489 
0490 %--------------------------------------------------------------------------
0491 % construct an ao from a function string
0492 %
0493 function a = aoFromFcn(pl, VERSION, ALGONAME)
0494 
0495 fcn = find(pl, 'fcn');
0496 
0497 % Make a cdata object
0498 ts = cdata(plist(param('fcn', fcn)));
0499 ts = set(ts, 'name', fcn);
0500 
0501 % Make an analysis object
0502 a.tag  = -1;
0503 a.name = fcn;
0504 a.data = ts;
0505 a.hist = history(ALGONAME, VERSION, pl);
0506 a.provenance  = provenance;
0507 a.comment     = '';
0508 a.mfile     = {};
0509 a.mfilename = '';
0510 a.mdlfile   = '';
0511 a.mdlfilename = '';
0512 a = class(a, 'ao');
0513 
0514 %--------------------------------------------------------------------------
0515 % construct an ao from filename
0516 %
0517 function a = aoFromFilename(filename, VERSION, ALGONAME)
0518 
0519 [path,fname,ext,versn] = fileparts(filename);
0520 switch ext
0521   case {'.txt','.dat'}
0522     disp(['  + creating AO from text file ' filename]);
0523 
0524     in = load(filename);
0525     t  = in(:,1);
0526     x  = in(:,2);
0527 
0528     % Make a tsdata object
0529     ts = tsdata(t,x);
0530     ts = set(ts, 'name', fname);
0531     ts = set(ts, 'xunits', 's');
0532     ts = set(ts, 'yunits', 'V');
0533 
0534     % Make an analysis object
0535     a.tag  = -1;
0536     a.name = fname;
0537     a.data = ts;
0538     a.hist = history(ALGONAME, VERSION, plist([param('filename', [fname ext]) param('filepath', path)]));
0539     a.provenance  = provenance;
0540     a.comment     = '';
0541     a.mfile     = {};
0542     a.mfilename = '';
0543     a.mdlfile   = '';
0544     a.mdlfilename = '';
0545     a = class(a, 'ao');
0546 
0547   case '.mat'
0548 %     disp('??? I do not work yet. Please code me up.');
0549 
0550     in = load(filename);
0551     fnames = fieldnames(in);
0552     eval(sprintf('a = in.%s;', fnames{1}));
0553 
0554   case '.xml'
0555 
0556     [tag, name, prov, comment, mfile, mfname, mdlfile, mdlfname, hist, data] = xml_read(filename);
0557     a.tag  = tag;
0558     a.name = name;
0559     a.data = data;
0560     a.hist = history(ALGONAME, VERSION, plist([param('filename', [fname ext]) param('filepath', path)]), hist);
0561     a.provenance  = prov;
0562     a.comment     = comment;
0563     a.mfile   = mfile;
0564     a.mfilename = mfname;
0565     a.mdlfile   = mdlfile;
0566     a.mdlfilename = mdlfname;
0567     a = class(a, 'ao');
0568 
0569   otherwise
0570     error('### unknown file type.');
0571 end
0572 
0573 %--------------------------------------------------------------------------
0574 % construct an ao from filename AND parameter list
0575 %
0576 function a = aoFromFilenameAndPlist(file_name, pl, VERSION, ALGONAME)
0577 
0578   a = [];
0579 
0580   disp(['  + creating AO from text file AND parameter list' file_name]);
0581 
0582   [pathstr, f_name, ext] = fileparts(file_name);
0583 
0584   pl_default = plist([param('columns',   [1 2])
0585                       param('type',     'tsdata')]);
0586   pl = combine(pl, pl_default);
0587 
0588   pl = append(pl, param('filename', [f_name ext]));
0589   pl = append(pl, param('filepath', pathstr));
0590 
0591   data_type = find (pl, 'type');
0592   columns   = find (pl, 'columns');
0593 
0594   f_data  = load(file_name);
0595 
0596   % the numbers in columns must be straight
0597   if mod(length(columns),2) ~= 0
0598     error('### the numbers in columns must be straight');
0599   end
0600 
0601   for lauf = 1:length(columns)/2
0602 
0603     data_x_axes = f_data(:, columns(lauf*2-1));
0604     data_y_axes = f_data(:, columns(lauf*2));
0605 
0606     %% create data object corresponding to the parameter list
0607     ao_data = [];
0608     switch data_type
0609       case 'tsdata'
0610         ao_data = tsdata( data_x_axes, data_y_axes);
0611       case 'fsdata'
0612         ao_data = fsdata( data_x_axes, data_y_axes);
0613       case 'cdata'
0614         error ('### please code me up')
0615       case 'xydata'
0616         ao_data = xydata( data_x_axes, data_y_axes);
0617       otherwise
0618         error(sprintf('### unknown data type ''%s''', data_type));
0619     end
0620 
0621     %% set fields of data from the parameter list
0622     field_names = fieldnames(ao_data);
0623     for ii = 1:length(pl.params)
0624       parameter = pl.params(ii);
0625       for jj = 1:max(size(field_names))
0626         if strcmp(parameter.key, field_names{jj})
0627 
0628           %% Tt is possible to give each data of an ao its own value.
0629           %% To do this store the values in a cell.
0630           %% e.g.: param('key', {value1, value2})
0631           %% The cell should have the same length of the new ao's. Is this not
0632           %% the case then the first cell is chosen.
0633           key = parameter.key;
0634           if iscell(parameter.val)
0635             if length(parameter.val) > 1
0636                if length(parameter.val) ~= length(columns)/2
0637                  warning([sprintf('The value of the key ''%s'' ',key)           ...
0638                                   'have not the same length as the lenthg of ' ...'
0639                                   'the output. Using the first value!']);
0640                  value = parameter.val{1};
0641                else
0642                  value = parameter.val{lauf};
0643                end
0644             else
0645               value = parameter.val{1};
0646             end
0647           else
0648             value = parameter.val;
0649           end
0650 
0651           if ischar(value)
0652             cmd = sprintf('ao_data = set(ao_data, ''%s'', ''%s'');', key, value);
0653           elseif isnumeric(value)
0654             cmd = sprintf('ao_data = set(ao_data, ''%s'', %s);', key, num2str(value));
0655           else
0656             % char(10) == return
0657             error ([char(10), '### aoFromFilenameAndPlist can not handle parameter value']);
0658           end
0659           eval(cmd);
0660         end
0661       end
0662     end
0663 
0664     aa      = [];
0665     aa.tag  = -1;
0666     aa.name = 'aoFromFilenameAndPlist';
0667     aa.data = ao_data;
0668     aa.hist = history(ALGONAME, VERSION, pl);
0669     aa.provenance  = provenance;
0670     aa.comment     = '';
0671     aa.mfile     = {};
0672     aa.mfilename = '';
0673     aa.mdlfile   = '';
0674     aa.mdlfilename = '';
0675     aa = class(aa, 'ao');
0676 
0677     a = [a aa];
0678 
0679   end
0680 
0681 
0682 %--------------------------------------------------------------------------
0683 % construct an ao from a Spectral window
0684 %
0685 function a = aoFromSpecWin(win, VERSION, ALGONAME)
0686 
0687 % Make a cdata object
0688 ts = cdata(win.win);
0689 ts = set(ts, 'name', win.name);
0690 
0691 % Make an analysis object
0692 a.tag  = -1;
0693 a.name = win.name;
0694 a.data = ts;
0695 a.hist = history(ALGONAME, VERSION, plist(param('win', win)));
0696 a.provenance  = provenance;
0697 a.comment     = '';
0698 a.mfile     = {};
0699 a.mfilename = '';
0700 a.mdlfile   = '';
0701 a.mdlfilename = '';
0702 a = class(a, 'ao');
0703 
0704 
0705 
0706 %--------------------------------------------------------------------------
0707 % construct an ao from server
0708 %
0709 function bs = aoFromServer(args, VERSION, ALGONAME);
0710 
0711 % retrieve ao from server
0712 bs = retrieve(args(2).val, [args(3:end).val]);
0713 
0714 % END

Generated on Wed 04-Jul-2007 19:03:10 by m2html © 2003