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;

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

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003