Home > classes > @ao > ao.m

ao

PURPOSE ^

AO analysis object class constructor.

SYNOPSIS ^

function varargout = ao(varargin)

DESCRIPTION ^

 AO analysis object class constructor.

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

 DESCRIPTION: AO analysis object class constructor.
              Create an analysis object.

     Properties:
       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 = '%'
                             'description'  To set the description 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, cdata, xydata, xyzdata.
       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('filename', 'a1.xml')

   'fcn'      - construct an AO from some valid MATLAB function.
                Example: plist('fcn', 'randn(100)')
                You can pass additional parameters to the fcn as extra
                parameters in the parameter list:
                plist('fcn', 'a*b', 'a', 2, 'b', 1:20);
 
                ** Note: case is ignored in the function specification
                such the following:
                  plist('fcn', 'a*A/b', 'a', 2, 'B', 1:20);
                results in:
                  2*2*[1:20]

   'vals'     - construct an AO from a set of values.
                Example: plist('vals', [1 2 3])
                optional parameter: repeat 'N' times 
                Example: plist('vals', [1 2 3], 'N', 10)

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

   'fsfcn'    - construct an AO from a function of frequency (f). You also
                need to specify:
                   'f1'    - the initial frequency
                   'f2'    - the final frequency
                   'nf'    - the number of frequency samples
                   'scale' - 'log' or 'lin' frequency spacing
                or provide a frequency vector:
                   'f' - a vector of frequencies on which to evaluate the
                         function

   'win'      - construct an AO from a specwin window function. Tjis
                creates a cdata type AO containing the window values.
                Example: plist('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)

   'Hostname' - construct an AO by retrieving it from an LTPDA repository
                specified by the given hostname. Only those objects which
                are AOs are returned.
                Additional parameters:
                'Database'   - The database name [default: 'ltpda']
                'ID'         - A vector of object IDs.

   'polyval'  - construct an AO using polynomial coefficients.
                Additional parameters:
                   'Nsecs' and 'fs'  - number of seconds, and sample rate
                or 't'               - vector of time vertices
  
                Example:  a = ao(plist('polyval', [1 2 3], 'Nsecs', 10, 'fs', 10);
 
 
   'Plist'    - construct from a plist. The value passed should be a plist
                object.
 
   Priority order for parameter names:  
          filename, fcn, vals, tsfcn, fsfcn, win, waveform, 
          hostname, polyval, plist
 

   Examples:

   1) Normally distributed random noise time-series

      p     = plist('waveform', 'noise', 'fs', 10, 'nsecs', 1000);
      rd10  = ao(p);



     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')

 The following call returns a string that contains the routine CVS version:

 >> version = ao(ao,'Version')

 The following call returns a string that contains the routine category:

 >> category = ao(ao,'Category')

 See also tsdata, fsdata, xydata, cdata, xyzdata

 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: AO analysis object class constructor.
0007 %              Create an analysis object.
0008 %
0009 %     Properties:
0010 %       name       - name of analysis object
0011 %       data       - data object (tsdata, fsdata)
0012 %       history    - history object
0013 %       provenance - creation info, machine, user, etc
0014 %
0015 %
0016 %     Possible constructors:
0017 %
0018 %       a = ao()            - creates an empty analysis object
0019 %       a = ao('a1.xml')    - creates a new analysis object by loading the
0020 %                             analysis object from disk.
0021 %       a = ao('file.txt')  - creates a new analysis object by loading the
0022 %       a = ao('file.dat')    data in 'file.txt'. The ascii file is assumed
0023 %                             to be an equally sampled two-column file of
0024 %                             time and amplitude. By default, the amplitude
0025 %                             units are taken to be Volts ('V') and the
0026 %                             time samples are assumed to be in seconds.
0027 %       a = ao('file',pl)   - creates a new analysis object by loading the
0028 %                             data in 'file'. The parameter list decide how the
0029 %                             analysis object is created. The valid key values
0030 %                             of the parameter list are:
0031 %                             'type'        'tsdata','fsdata','xydata'
0032 %                                            default = 'tsdata'
0033 %                             'use_fs'       if this value is set, the
0034 %                                            x-axes is computed by the fs value.
0035 %                             'columns'      [1 2 1 4]
0036 %                                            default = [1 2]
0037 %                                            Each pair represented the x- and y-axes.
0038 %                                            (Each column pair creates an analysis object)
0039 %                                            Is the value 'use_fs' is used then
0040 %                                            represent each column the y-axes.
0041 %                                            (Each column creates an analysis object)
0042 %                             'num_columns'  Maximum colums in the file
0043 %                                            default = 10
0044 %                             'comment_char' The comment character in the file
0045 %                                            default = '%'
0046 %                             'description'  To set the description in the analysis object
0047 %                             '...'          every property of the data object
0048 %                                            e.g. 'name'
0049 %                             If the constructor creates multiple ao's it is
0050 %                             possible to give each data class its own e.g.
0051 %                             'name'. In this case the parameter list with the
0052 %                             key 'name' must have cell of the different values
0053 %                             as the name of the different data objects. e.g.
0054 %                             pl = plist('columns', [1 2 1 3],        ...
0055 %                                        'name',   {'name1' 'name2'}, ...
0056 %                                        'xunits', 'sec',             ...
0057 %                                        'yunits', {'V' 'Hz'});
0058 %                             This parameter list creates two ao's with tsdata.
0059 %       a = ao(plist)       - creates an analysis object with by reading
0060 %                             the file specified by the 'filename'
0061 %                             parameter in the plist.
0062 %       a = ao(data)        - creates an analysis object with a data
0063 %                             object. Data object can be one of tsdata,
0064 %                             fsdata, cdata, xydata, xyzdata.
0065 %       a = ao(data, hist)  - creates an analysis object with a data
0066 %                             object and a history object
0067 %
0068 %       a = ao(specwin)     - creates an analysis object from a specwin
0069 %                             object
0070 %
0071 % Parameters for plist constructor:
0072 %
0073 %   'filename' - construct an AO from a filename.
0074 %                Example: plist('filename', 'a1.xml')
0075 %
0076 %   'fcn'      - construct an AO from some valid MATLAB function.
0077 %                Example: plist('fcn', 'randn(100)')
0078 %                You can pass additional parameters to the fcn as extra
0079 %                parameters in the parameter list:
0080 %                plist('fcn', 'a*b', 'a', 2, 'b', 1:20);
0081 %
0082 %                ** Note: case is ignored in the function specification
0083 %                such the following:
0084 %                  plist('fcn', 'a*A/b', 'a', 2, 'B', 1:20);
0085 %                results in:
0086 %                  2*2*[1:20]
0087 %
0088 %   'vals'     - construct an AO from a set of values.
0089 %                Example: plist('vals', [1 2 3])
0090 %                optional parameter: repeat 'N' times
0091 %                Example: plist('vals', [1 2 3], 'N', 10)
0092 %
0093 %   'tsfcn'    - construct an AO from a function of time. You need to also
0094 %                specify parameters 'fs' and 'nsecs' for this call.
0095 %                Example:
0096 %                plist('fs', 10, 'nsecs', 10, 'tsfcn', 'sin(2*pi*1.4*t) + 0.1*randn(size(t))')
0097 %
0098 %   'fsfcn'    - construct an AO from a function of frequency (f). You also
0099 %                need to specify:
0100 %                   'f1'    - the initial frequency
0101 %                   'f2'    - the final frequency
0102 %                   'nf'    - the number of frequency samples
0103 %                   'scale' - 'log' or 'lin' frequency spacing
0104 %                or provide a frequency vector:
0105 %                   'f' - a vector of frequencies on which to evaluate the
0106 %                         function
0107 %
0108 %   'win'      - construct an AO from a specwin window function. Tjis
0109 %                creates a cdata type AO containing the window values.
0110 %                Example: plist('win', specwin('Hannning', 100))
0111 %
0112 %   'waveform' - construct an AO from a waveform description. Here you need
0113 %                to specify additional parameters 'fs' and 'nsecs', and also,
0114 %                for the following waveform types:
0115 %                'sine wave'      - 'f', 'phi'
0116 %                'noise'          - 'type' (can be 'Normal' or 'Uniform')
0117 %                'chirp'          - 'f0', 'f1', 't1'      (help chirp)
0118 %                'Gaussian pulse' - 'f0', 'bw'            (help gauspuls)
0119 %                'Square wave'    - 'f', 'duty'           (help square)
0120 %                'Sawtooth'       - 'f', 'width'          (help sawtooth)
0121 %
0122 %   'Hostname' - construct an AO by retrieving it from an LTPDA repository
0123 %                specified by the given hostname. Only those objects which
0124 %                are AOs are returned.
0125 %                Additional parameters:
0126 %                'Database'   - The database name [default: 'ltpda']
0127 %                'ID'         - A vector of object IDs.
0128 %
0129 %   'polyval'  - construct an AO using polynomial coefficients.
0130 %                Additional parameters:
0131 %                   'Nsecs' and 'fs'  - number of seconds, and sample rate
0132 %                or 't'               - vector of time vertices
0133 %
0134 %                Example:  a = ao(plist('polyval', [1 2 3], 'Nsecs', 10, 'fs', 10);
0135 %
0136 %
0137 %   'Plist'    - construct from a plist. The value passed should be a plist
0138 %                object.
0139 %
0140 %   Priority order for parameter names:
0141 %          filename, fcn, vals, tsfcn, fsfcn, win, waveform,
0142 %          hostname, polyval, plist
0143 %
0144 %
0145 %   Examples:
0146 %
0147 %   1) Normally distributed random noise time-series
0148 %
0149 %      p     = plist('waveform', 'noise', 'fs', 10, 'nsecs', 1000);
0150 %      rd10  = ao(p);
0151 %
0152 %
0153 %
0154 %     Indexing:
0155 %       b = a(1)            % where a is an array of analysis objects
0156 %       d = a.data;         % get the data object
0157 %       h = a.hist;         % get the history object
0158 %       d = a.data.x(1:20); % get a matrix of data values x;
0159 %
0160 % The following call returns a parameter list object that contains the
0161 % default parameter values:
0162 %
0163 % >> pl = ao(ao, 'Params')
0164 %
0165 % The following call returns a string that contains the routine CVS version:
0166 %
0167 % >> version = ao(ao,'Version')
0168 %
0169 % The following call returns a string that contains the routine category:
0170 %
0171 % >> category = ao(ao,'Category')
0172 %
0173 % See also tsdata, fsdata, xydata, cdata, xyzdata
0174 %
0175 % M Hewitson 30-01-07
0176 %
0177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0178 
0179 %       a = ao('object.mat') - creates a new analysis object by loading the
0180 %                             analysis object from disk .
0181 
0182 ALGONAME = mfilename;
0183 VERSION  = '$Id: ao.m,v 1.85 2008/03/04 08:46:53 hewitson Exp $';
0184 CATEGORY = 'Constructor';
0185 
0186 %%% Check if this is a special call: default parameter list, cvs-version,
0187 if  (nargin == 2 || nargin == 3) &&...
0188     isa(varargin{1}, 'ao') &&...
0189     ischar(varargin{2})
0190   if strcmp(varargin{2}, 'Params')
0191     if nargin == 2
0192       varargout{1} = getDefaultPlist();
0193     else
0194       varargout{1} = getDefaultPlist(varargin{3});
0195     end
0196     return
0197   elseif strcmp(varargin{2}, 'Version')
0198     varargout{1} = VERSION;
0199     return
0200   elseif strcmp(varargin{2}, 'Category')
0201     varargout{1} = CATEGORY;
0202     return
0203   end
0204 end
0205 
0206 
0207 % process input arguments
0208 args = [];
0209 k = 0;
0210 pls = [];
0211 for j=1:nargin
0212   if ~isempty(varargin{j})
0213     k = k + 1;
0214     if isa(varargin{j}, 'plist')
0215       pls = [pls varargin{j}];
0216     else
0217       args(k).val = varargin{j};
0218       args(k).n   = j;
0219     end
0220   end
0221 end
0222 
0223 % We could have multiple input plist objects. Combine them here.
0224 if isa(pls, 'plist')
0225   pl = combine(pls);
0226 else
0227   pl = [];
0228 end
0229 
0230 Nargs = length(args);
0231 if ~isempty(pl)
0232   args(Nargs+1).val = pl;
0233   args(Nargs+1).n   = j+1;
0234   Nargs = length(args);
0235 end
0236 
0237 %%%%%%%%%%%%%%%%%%%%   define parameter properties list   %%%%%%%%%%%%%%%%%%%%%
0238 
0239   function a = init()
0240     a.name        = 'None';
0241     a.data        = {};
0242     a.hist        = history(ALGONAME, VERSION);
0243     a.provenance  = provenance;
0244     a.description = '';
0245     a.mfile       = '';
0246     a.mfilename   = '';
0247     a.mdlfile     = '';
0248     a.mdlfilename = '';
0249     a.plist       = plist();
0250     a.version     = VERSION;
0251     a.created     = time;
0252     a = class(a, 'ao');
0253   end
0254 
0255 
0256 %%%%%%%%%%%%%%%%%%%%%%%%%   Create analysis object   %%%%%%%%%%%%%%%%%%%%%%%%%%
0257 
0258 %%%%%%%%%%   pl = ao()   %%%%%%%%%%
0259 if Nargs == 0
0260 
0261   varargout{1} = init();
0262 
0263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0264 %%%                              One Parameter                              %%%
0265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0266 elseif Nargs == 1              % create ao with data
0267 
0268   %%%%%%%%%%   a1 = ao('foo.mat')   %%%%%%%%%%
0269   %%%%%%%%%%   a1 = ao('foo.xml')   %%%%%%%%%%
0270   if ischar(args(1).val)
0271 
0272     a = init();
0273 
0274     filename = args(1).val;
0275     [path, name, ext, vers] = fileparts(filename);
0276     switch ext
0277       case '.mat'
0278         a = load(filename);
0279         a = a.a;
0280         a.name = strcat(name, ext);
0281       case '.xml'
0282         root_node = xmlread(filename);
0283         a = ltpda_xmlread(root_node, 'ao');
0284       case {'.txt', '.dat'}
0285         a = aoFromFilenameAndPlist(a, args(1).val, plist(), VERSION, ALGONAME);
0286         a.name = strcat(name, ext);
0287       otherwise
0288         error('### Unknown file type.');
0289     end
0290     varargout{1} = a;
0291 
0292   %%%%%%%%%%   a1 = ao(ao)   %%%%%%%%%%
0293   elseif isa(args(1).val, 'ao')
0294     varargout{1} = args(1).val;
0295 
0296   %%%%%%%%%%   a1 = ao(struct)   %%%%%%%%%%
0297   % create from struct
0298   elseif isstruct(args(1).val)
0299     a       = init();
0300     astruct = args(1).val;
0301     a.name  = astruct.name;
0302     data    = astruct.data;
0303 
0304     if isstruct(data)
0305       if isfield(data, {'t', 'x'})
0306         data = tsdata(data);
0307       elseif isfield(data, {'f', 'xx'})
0308         data = fsdata(data);
0309       elseif isfield(data, {'vals'})
0310         data = cdata(data);
0311       elseif isfield(data, {'x', 'y'})
0312         data = xydata(data);
0313       elseif isfield(data, {'x', 'y', 'z'})
0314         data = xyzdata(data);
0315       else
0316         error('### Unknown data type in input structure.');
0317       end
0318     end
0319 
0320     a.data = data;
0321     hist   = astruct.hist;
0322     if isstruct(hist)
0323       hist = history(hist);
0324     end
0325     a.hist = hist;
0326     prov = astruct.provenance;
0327     if isstruct(prov)
0328       prov = provenance(prov);
0329     end
0330 
0331     a.provenance  = prov;
0332     a.description = astruct.description;
0333     a.mfile       = astruct.mfile;
0334     a.mfilename   = astruct.mfilename;
0335     a.mdlfile     = astruct.mdlfile;
0336     a.mdlfilename = astruct.mdlfilename;
0337     a.plist       = astruct.plist;
0338     a.version     = astruct.version;
0339     created       = astruct.created;
0340     if isstruct(created)
0341       created = time(created);
0342     end
0343     a.created     = created;
0344     varargout{1}  = a;
0345 
0346   %%%%%%%%%%   a1 = ao(1)   %%%%%%%%%%
0347   % create from constant
0348   elseif isnumeric(args(1).val)
0349 
0350     a      = init();
0351     a.data = cdata(args(1).val);
0352     a.hist = history(ALGONAME, VERSION, plist(param('vals', args(1).val)));
0353 
0354     varargout{1}  = a;
0355 
0356   %%%%%%%%%%   a1 = ao(plist)   %%%%%%%%%%
0357   % create data using plist
0358   elseif isa(args(1).val, 'plist')
0359 
0360     pl       = args(1).val;
0361     filename = find(pl, 'filename');
0362     fcn      = find(pl, 'fcn');
0363     vals     = find(pl, 'vals');
0364     tsfcn    = find(pl, 'tsfcn');
0365     fsfcn    = find(pl, 'fsfcn');
0366     win      = find(pl, 'win');
0367     waveform = find(pl, 'waveform');
0368     polycoeffs = find(pl, 'polyval');
0369     hostname = find(pl, 'hostname');
0370     ipl      = find(pl, 'Plist');
0371 
0372     a = init();
0373     a.plist = pl;
0374     
0375     if ~isempty(filename)
0376       % do filename constructor
0377       [path, name, ext, vers] = fileparts(filename);
0378       switch ext
0379         case '.mat'
0380           a = load(filename);
0381           varargout{1} = a.a;
0382         case '.xml'
0383           root_node = xmlread(filename);
0384           a = ltpda_xmlread(root_node, 'ao');
0385           varargout{1} = a;
0386         case {'.txt', '.dat'}
0387           ao_out = aoFromFilenameAndPlist(a, filename, pl, VERSION, ALGONAME);
0388           if nargout == 1
0389             varargout{1} = ao_out;
0390           elseif nargout == length(ao_out)
0391             for ii = 1:length(ao_out)
0392               varargout{ii} = ao_out(ii);
0393             end
0394           else
0395             warning ('### Too few output variables --> useing only the first.');
0396             varargout{1} = ao_out;
0397           end
0398         otherwise
0399           error('### Unknown file type.');
0400       end
0401 
0402     elseif ~isempty(fcn)
0403       % do function constructor
0404       varargout{1} = aoFromFcn(a, pl, VERSION, ALGONAME);
0405 
0406     elseif ~isempty(vals)
0407       % do vals constructor
0408       varargout{1} = aoFromVals(a, pl, VERSION, ALGONAME);
0409     elseif ~isempty(tsfcn)
0410       % do tsfcn constructor
0411       varargout{1} = aoFromTSfcn(a, pl, VERSION, ALGONAME);
0412     elseif ~isempty(fsfcn)
0413       % do fsfcn constructor
0414       varargout{1} = aoFromFSfcn(a, pl, VERSION, ALGONAME);
0415     elseif ~isempty(win)
0416       % do win constructor
0417       varargout{1} = aoFromSpecWin(a, win, VERSION, ALGONAME);
0418     elseif ~isempty(waveform)
0419       % do waveform constructor
0420       varargout{1} = aoFromWaveform(a, pl, VERSION, ALGONAME);
0421     elseif ~isempty(hostname)
0422       % do hostname constructor
0423       varargout{1} = aoFromRepository(a, pl, VERSION, ALGONAME);
0424     elseif ~isempty(polycoeffs)
0425       % do polyval constructor
0426       varargout{1} = aoFromPolyval(a, pl, VERSION, ALGONAME);
0427     elseif ~isempty(ipl)
0428       % do plist constructor
0429       varargout{1} = ao(ipl);
0430     else
0431       error('### Unknown AO constructor method.');
0432     end
0433 
0434   %%%%%%%%%%   a1 = ao(specwin)   %%%%%%%%%%
0435   % create from spectral window
0436   elseif isa(args(1).val, 'specwin')
0437     a = init();
0438     varargout{1} = aoFromSpecWin(a, args(1).val, VERSION, ALGONAME);
0439 
0440   %%%%%%%%%%   a1 = ao(cdata)    %%%%%%%%%%
0441   %%%%%%%%%%   a1 = ao(fsdata)   %%%%%%%%%%
0442   %%%%%%%%%%   a1 = ao(tsdata)   %%%%%%%%%%
0443   %%%%%%%%%%   a1 = ao(xydata)   %%%%%%%%%%
0444   % create from data object
0445   else
0446     a = init();
0447     data          = args(1).val;
0448     a.data        = data;
0449     a.hist        = history(ALGONAME, VERSION);
0450 
0451     if ~isa(a.data, 'tsdata') &&...
0452        ~isa(a.data, 'fsdata') &&...
0453        ~isa(a.data, 'cdata')  &&...
0454        ~isa(a.data, 'xydata')  &&...
0455        ~isa(a.data, 'xyzdata')
0456       error('### unknown data object.')
0457     end
0458     varargout{1} = a;
0459   end
0460 
0461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0462 %%%                              Two Parameter                              %%%
0463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0464 
0465 elseif Nargs == 2
0466 
0467   %%%%%%%%%%   Database   %%%%%%%%%%
0468   if isa(varargin{1}, 'database')
0469     varargout{1} = retrieve(varargin{1}, varargin{2:end});
0470 
0471   %%%%%%%%%%%   ao('foo.txt', pl)   %%%%%%%%%%
0472   elseif ischar(args(1).val) && isa(args(2).val, 'plist')
0473 
0474     a = init();
0475 
0476     ao_out = aoFromFilenameAndPlist(a, args(1).val, args(2).val, VERSION, ALGONAME);
0477 
0478     for ii = numel(ao_out)
0479       ao_out(ii).plist = args(2).val;
0480       ao_out(ii).name = args(1).val;
0481     end
0482 
0483     if nargout == 1
0484       varargout{1} = ao_out;
0485     elseif nargout == length(ao_out)
0486       for ii = 1:length(ao_out)
0487         varargout{ii} = ao_out(ii);
0488       end
0489     else
0490       warning ('### Too few output variables --> useing only the first.');
0491       varargout{1} = ao_out;
0492     end
0493 
0494   %%%%%%%%%%%   ao(data-object, history-object)   %%%%%%%%%%
0495   else
0496 
0497     a = init();
0498 
0499     a.data        = args(1).val;
0500     a.hist        = args(2).val; %history(ALGONAME, VERSION, [], varargin{2});
0501 
0502     if ~isa(a.data, 'tsdata') &&...
0503         ~isa(a.data, 'fsdata') &&...
0504         ~isa(a.data, 'cdata')  &&...
0505         ~isa(a.data, 'xydata')
0506       error('### unknown data object.')
0507     end
0508     if ~isa(a.hist, 'history')
0509       error('### unknown history object.')
0510     end
0511 
0512     varargout{1} = a;
0513 
0514   end
0515 
0516 
0517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0518 %%%                             Nine Parameter                              %%%
0519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0520 %  full constructor - all fields
0521 elseif Nargs == 9
0522 
0523   a = init();
0524   a.name        = args(1).val;
0525   a.data        = args(2).val;
0526   a.hist        = args(3).val;
0527   a.provenance  = args(4).val;
0528   a.description = args(5).val;
0529   a.mfile       = args(6).val;
0530   a.mfilename   = args(7).val;
0531   a.mdlfile     = args(8).val;
0532   a.mdlfilename = args(9).val;
0533   varargout{1}  = a;
0534 
0535 else
0536   error('### Unknown number of constructor arguments.');
0537 end
0538 
0539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0540 %
0541 % FUNCTION:    aoFromRepository
0542 %
0543 % DESCRIPTION: Construct an ao from a repository
0544 %
0545 % CALL:        aos = aoFromRepository(a, pl, VERSION, ALGONAME)
0546 %
0547 % PARAMETER:   a:        Initialised analysis object
0548 %              pl:       Parameter list object
0549 %              VERSION:  cvs version string
0550 %              ALGONAME: The m-file name (use the mfilename command)
0551 %
0552 % HISTORY:     07-05-2007 Hewitson
0553 %              Creation
0554 %
0555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0556 function aos = aoFromRepository(a, pl, VERSION, ALGONAME)
0557 
0558   dpl = getDefaultPlist('From Repository');
0559   pl  = combine(pl, dpl);
0560 
0561   % Get parameters
0562   conn = find(pl, 'conn');
0563   hostname = find(pl, 'hostname');
0564   database = find(pl, 'database');
0565   ids      = find(pl, 'id');
0566   
0567   % do we have a connection?
0568   closeConn = 0;
0569   if isempty(conn)
0570     closeConn = 1;
0571     % Connect to repository
0572     conn = mysql_connect(hostname, database);
0573   end
0574   if ~isa(conn, 'database')
0575     error('### connection failed.');
0576   end
0577   
0578   % Get each ID
0579   Nids = length(ids);
0580   aos  = [];
0581   for kk=1:Nids
0582 
0583     %---- This id
0584     id = ids(kk);
0585     disp(sprintf('  - retrieving ID %d', id));
0586 
0587     %---- check ID object type
0588     tt = mysql_getObjType(conn, id);
0589     %---- If this is an AO
0590     if strcmp(tt, mfilename)
0591       %---- call database constructor
0592       a = ltpda_obj_retrieve(conn, id);
0593       %---- Add history
0594 
0595       % make a new history object
0596       %  - remove connection object from plist first
0597       h = history(ALGONAME, VERSION, remove(pl, 'conn'), a.hist);
0598 
0599       % set this to the AO
0600       a = setnh(a, 'hist', h);
0601 
0602       %---- Add to output array
0603       aos = [aos a];
0604     else
0605       warning('    !skipping ID %d, type %s', id, tt);
0606     end
0607 
0608   end
0609 
0610   % close connection
0611   if closeConn
0612     close(conn);
0613   end
0614 end
0615 
0616 
0617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0618 %
0619 % FUNCTION:    aoFromPolyval
0620 %
0621 % DESCRIPTION: Construct a time-series ao from polynomial coefficients
0622 %
0623 % CALL:        a = aoFromPolyval(a, vals, VERSION, ALGONAME)
0624 %
0625 % PARAMETER:   a:        Initialised analysis object
0626 %              pl:       plist containing 'polyval', 'Nsecs', 'fs', or 't'
0627 %              VERSION:  cvs version string
0628 %              ALGONAME: The m-file name (use the mfilename command)
0629 %
0630 % HISTORY:     07-05-2007 Hewitson
0631 %              Creation
0632 %
0633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0634 function a = aoFromPolyval(a, pl, VERSION, ALGONAME)
0635 
0636   coeffs = find(pl, 'polyval');
0637   Nsecs  = find(pl, 'Nsecs');
0638   fs     = find(pl, 'fs');
0639   t      = find(pl, 't');
0640   
0641   % Check t vector
0642   if isempty(t)
0643     if isempty(Nsecs) || isempty(fs)
0644       error('### Please provide either ''Nsecs'' and ''fs'', or ''t'' for polyval constructor.');
0645     end    
0646     t = linspace(0, Nsecs - 1/fs, Nsecs*fs);    
0647   end
0648     
0649   y = polyval(coeffs,t);
0650 
0651   % Make a cdata object
0652   ts = tsdata(t, y);
0653   ts = set(ts, 'name', 'Polyval');
0654   ts = set(ts, 'xunits', 's');
0655   ts = set(ts, 'yunits', 'V');
0656   
0657   % Make an analysis object
0658   a.data = ts;
0659   a.hist = history(ALGONAME, VERSION, pl);
0660 end
0661 
0662 
0663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0664 %
0665 % FUNCTION:    aoFromVals
0666 %
0667 % DESCRIPTION: Construct an ao from a value set
0668 %
0669 % CALL:        a = aoFromVals(a, vals, VERSION, ALGONAME)
0670 %
0671 % PARAMETER:   a:        Initialised analysis object
0672 %              vals:     Constant values
0673 %              VERSION:  cvs version string
0674 %              ALGONAME: The m-file name (use the mfilename command)
0675 %
0676 % HISTORY:     07-05-2007 Hewitson
0677 %              Creation
0678 %
0679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0680 function a = aoFromVals(a, pl, VERSION, ALGONAME)
0681 
0682   vals = find(pl, 'vals');
0683   N    = find(pl, 'N');
0684   if isempty(N)
0685     N = 1;
0686   end
0687     
0688   if ischar(vals)
0689     try
0690       vals = eval(vals);
0691     catch
0692       error('Could not convert char array to numeric array.');
0693     end
0694   end
0695 
0696   % Make a cdata object
0697   ts = cdata(plist(param('vals', repmat(vals, 1, N))));
0698   ts = set(ts, 'name', 'Vals');
0699 
0700   % Make an analysis object
0701   a.data = ts;
0702   a.hist = history(ALGONAME, VERSION, pl);
0703 end
0704 
0705 
0706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0707 %
0708 % FUNCTION:    aoFromWaveform
0709 %
0710 % DESCRIPTION: Construct an ao from a waveform
0711 %
0712 % CALL:        a = aoFromWaveform(a, pl, VERSION, ALGONAME)
0713 %
0714 % PARAMETER:   a:        Initialised analysis object
0715 %              pl:       Parameter list object
0716 %              VERSION:  cvs version string
0717 %              ALGONAME: The m-file name (use the mfilename command)
0718 %
0719 % HISTORY:     07-05-2007 Hewitson
0720 %              Creation
0721 %
0722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0723 function a = aoFromWaveform(a, pl, VERSION, ALGONAME)
0724 
0725   nsecs  = find(pl, 'nsecs');
0726   fs     = find(pl, 'fs');
0727   t0     = find(pl, 't0');
0728   if isempty(t0)
0729     t0 = time(0);
0730   end
0731   
0732   waveform = find(pl, 'waveform');
0733   switch waveform
0734     %------------ Sine Wave
0735     case 'sine wave'
0736       freq = find(pl, 'f');
0737       phi  = find(pl, 'phi');
0738       if isempty(freq)
0739         freq = 1;
0740       end
0741       if isempty(phi)
0742         phi = 0;
0743       end
0744       tsfcn = sprintf('sin(2*pi*%g*t + %g*pi/180)', freq, phi);
0745       %------------ Noise
0746     case 'noise'
0747       ntype = find(pl, 'type');
0748       if isempty(ntype)
0749         ntype = 'Normal';
0750       end
0751       switch ntype
0752         case 'Normal'
0753           tsfcn = 'randn(size(t))';
0754         case 'Uniform'
0755           tsfcn = 'rand(size(t))';
0756       end
0757       %------------ Chirp
0758     case 'chirp'
0759       f0  = find(pl, 'f0');
0760       fe  = find(pl, 'f1');
0761       te  = find(pl, 't1');
0762       if isempty(f0)
0763         f0 = 0;
0764       end
0765       if isempty(fe)
0766         fe = fs/2;
0767       end
0768       if isempty(te)
0769         te = nsecs;
0770       end
0771       tsfcn = sprintf('chirp(t,%g,%g,%g)', f0, fe, te);
0772       %------------ Gaussian pulse
0773     case 'Gaussian pulse'
0774       fc  = find(pl, 'f0');
0775       bw  = find(pl, 'bw');
0776       if isempty(fc)
0777         fc = 1;
0778       end
0779       if isempty(bw)
0780         bw = fs/2;
0781       end
0782       tsfcn = sprintf('gauspuls(t,%g,%g)', fc, bw);
0783     case 'Square wave'
0784       freq = find(pl, 'f');
0785       duty = find(pl, 'duty');
0786       if isempty(freq)
0787         freq = 1;
0788       end
0789       if isempty(duty)
0790         duty = 50;
0791       end
0792       tsfcn = sprintf('square(2*pi*%g*t,%g)', freq, duty);
0793     case 'Sawtooth'
0794       freq  = find(pl, 'f');
0795       width = find(pl, 'width');
0796       if isempty(freq)
0797         freq = 1;
0798       end
0799       if isempty(width)
0800         width = 0.5;
0801       end
0802       tsfcn = sprintf('sawtooth(2*pi*%g*t,%g)', freq, width);
0803   end
0804 
0805 
0806   % construct tsdata
0807   t = linspace(0, nsecs-1/fs, nsecs*fs);
0808   % make y data
0809   y = eval([tsfcn ';']);
0810 
0811   ts = tsdata(t,y);
0812   ts = set(ts, 'name', tsfcn);
0813   ts = set(ts, 'xunits', 's');
0814   ts = set(ts, 'yunits', 'V');
0815   ts = set(ts, 't0', t0);
0816 
0817   % Make an analysis object
0818   a.name = waveform;
0819   a.data = ts;
0820   a.hist = history(ALGONAME, VERSION, pl);
0821 end
0822 
0823 
0824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0825 %
0826 % FUNCTION:    aoFromTSfcn
0827 %
0828 % DESCRIPTION: Construct an ao from a ts-function string
0829 %
0830 % CALL:        a = aoFromTSfcn(a, pl, VERSION, ALGONAME)
0831 %
0832 % PARAMETER:   a:        Initialised analysis object
0833 %              pl:       Parameter list object
0834 %              VERSION:  cvs version string
0835 %              ALGONAME: The m-file name (use the mfilename command)
0836 %
0837 % HISTORY:     07-05-2007 Hewitson
0838 %              Creation
0839 %
0840 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0841 function a = aoFromTSfcn(a, pl, VERSION, ALGONAME)
0842 
0843   nsecs       = find(pl, 'nsecs');
0844   fs          = find(pl, 'fs');
0845   fcn         = find(pl, 'tsfcn');
0846   randn_state = find(pl, 'rand_state');
0847   t0          = find(pl, 't0');
0848   if isempty(t0)
0849     t0 = time(0);
0850   end
0851 
0852   % construct tsdata
0853   t = linspace(0, nsecs-1/fs, nsecs*fs);
0854 
0855   % make y data
0856 
0857   % If the randn state is in the parameter list then set the randn function to
0858   % this sate
0859   if ~isempty(randn_state)
0860     randn('state',randn_state);
0861   else % Store the state of the random function in the parameter list
0862     randn_state = randn('state');
0863     pl = append(pl , 'rand_state', randn_state);
0864   end
0865 
0866   y = eval([fcn ';']);
0867 
0868   ts = tsdata(t,y);
0869   ts = set(ts, 'name', fcn);
0870   ts = set(ts, 'xunits', 's');
0871   ts = set(ts, 'yunits', 'V');
0872   ts = set(ts, 't0', t0);
0873   
0874   % Make an analysis object
0875   a.data = ts;
0876   a.hist = history(ALGONAME, VERSION, pl);
0877 end
0878 
0879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0880 %
0881 % FUNCTION:    aoFromFSfcn
0882 %
0883 % DESCRIPTION: Construct an ao from a fs-function string
0884 %
0885 % CALL:        a = aoFromFSfcn(a, pl, VERSION, ALGONAME)
0886 %
0887 % PARAMETER:   a:        Initialised analysis object
0888 %              pl:       Parameter list object
0889 %              VERSION:  cvs version string
0890 %              ALGONAME: The m-file name (use the mfilename command)
0891 %
0892 % HISTORY:     07-05-2007 Hewitson
0893 %              Creation
0894 %
0895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0896 function a = aoFromFSfcn(a, pl, VERSION, ALGONAME)
0897 
0898   dpl = getDefaultPlist('Frequency-series Function');
0899   pl  = combine(pl, dpl);
0900   f   = find(pl, 'f');
0901   if isempty(f)
0902     disp('--- generating f')
0903     f1 = find(pl, 'f1');
0904     f2 = find(pl, 'f2');
0905     nf = find(pl, 'nf');
0906     scale = find(pl, 'scale');
0907     switch scale
0908       case 'log'
0909         f = logspace(log10(f1), log10(f2), nf);
0910       case 'lin'
0911         f = linspace(f1, f2, nf);
0912       otherwise
0913         error('### Unknown frequency scale specified');
0914     end
0915   end
0916 
0917   % Get the function
0918   fcn  = find(pl, 'fsfcn');
0919 
0920   % make y data
0921   y = eval([fcn ';']);
0922 
0923   fs = fsdata(f,y);
0924   fs = set(fs, 'name', fcn);
0925   fs = set(fs, 'xunits', 'Hz');
0926   fs = set(fs, 'yunits', 'Arb');
0927 
0928   % Make an analysis object
0929   a.data = fs;
0930   a.hist = history(ALGONAME, VERSION, pl);
0931 end
0932 
0933 
0934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0935 %
0936 % FUNCTION:    aoFromFcn
0937 %
0938 % DESCRIPTION: Construct an ao from a function string
0939 %
0940 % CALL:        a = aoFromFcn(a, pl, VERSION, ALGONAME)
0941 %
0942 % PARAMETER:   a:        Initialised analysis object
0943 %              pl:       Parameter list object
0944 %              VERSION:  cvs version string
0945 %              ALGONAME: The m-file name (use the mfilename command)
0946 %
0947 % HISTORY:     07-05-2007 Hewitson
0948 %              Creation
0949 %
0950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0951 function a = aoFromFcn(a, pl, VERSION, ALGONAME)
0952 
0953   fcn = find(pl, 'fcn');
0954   
0955   % find all other parameters and try to evaluate them
0956   for jj=1:nparams(pl)
0957     p = pl.params(jj);
0958     if ~strcmpi(fcn, p.val)
0959       % try upper case replacement
0960       fcn = strrep(fcn, p.key, mat2str(p.val));
0961       % try lower case replacement
0962       fcn = strrep(fcn, lower(p.key), mat2str(p.val));
0963     end
0964   end
0965   
0966   % Make a cdata object
0967   ts = cdata(plist(param('fcn', fcn)));
0968   ts = set(ts, 'name', fcn);
0969 
0970   % Make an analysis object
0971   a.data = ts;
0972   a.hist = history(ALGONAME, VERSION, pl);
0973 end
0974 
0975 
0976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0977 %
0978 % FUNCTION:    aoFromFilenameAndPlist
0979 %
0980 % DESCRIPTION: Construct an ao from filename AND parameter list
0981 %
0982 % CALL:        a = aoFromFilenameAndPlist(init_ao, file_name, pl, VERSION, ALGONAME)
0983 %
0984 % PARAMETER:   init_ao:   Initialised analysis object
0985 %              file_name: File name
0986 %              pl:        Parameter list object
0987 %              VERSION:   cvs version string
0988 %              ALGONAME:  The m-file name (use the mfilename command)
0989 %
0990 % HISTORY:     07-05-2007 Hewitson
0991 %              Creation
0992 %
0993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0994 function a = aoFromFilenameAndPlist(init_ao, file_name, pl, VERSION, ALGONAME)
0995 
0996   a = [];
0997 
0998   [pathstr, f_name, ext] = fileparts(file_name);
0999 
1000   %%%%%%%%%%   Define default parameter list   %%%%%%%%%%
1001   pl_default = plist('columns',      [1 2],    ...
1002                      'num_columns',   10,      ...
1003                      'type',         'tsdata', ...
1004                      'use_fs',       '',       ...
1005                      'comment_char', '%',      ...
1006                      'xunits',       'sec',    ...
1007                      'yunits',       'V');
1008   pl = combine(pl, pl_default);
1009 
1010   pl = pset(pl, param('filename', [f_name ext]));
1011   pl = pset(pl, param('filepath', pathstr));
1012 
1013   data_type    = find (pl, 'type');
1014   columns      = find (pl, 'columns');
1015   num_columns  = find (pl, 'num_columns');
1016   comment_char = find (pl, 'comment_char');
1017   use_fs       = find (pl, 'use_fs');
1018   xunits       = find (pl, 'xunits');
1019   yunits       = find (pl, 'yunits');
1020   t0           = find (pl, 't0');
1021   
1022   %%%%%%%%%%   read file   %%%%%%%%%%
1023   [fid,msg] = fopen (file_name, 'r');
1024   if (fid < 0)
1025     error ('### can not open file: %s \n\n### error msg:',file_name, msg);
1026   end
1027 
1028   %%%%%%%%%% create scan format: '%f %f %f %f %f'   %%%%%%%%%%
1029   scan_format = [];
1030   for ii=1:num_columns
1031     scan_format = [scan_format '%f '];
1032   end
1033   scan_format = scan_format(1:end-1); % remove the last whitespace
1034 
1035   %%%%%%%%%%   scan the file   %%%%%%%%%%
1036   raw_data = textscan( fid, scan_format,             ...
1037                       'commentStyle',  comment_char, ...
1038                       'CollectOutput', 1);
1039   f_data = raw_data{1};
1040 
1041   if isempty(f_data)
1042     error([char(10) '### There are no data. ' ...
1043                     'Did you use the right comment character?'            char(10) ...
1044                     '### The current comment character is: ' comment_char char(10) ...
1045                     '### Use a parameter list with the parameter:'        char(10) ...
1046                     '### plist(''comment_char'', ''%'')']);
1047   end
1048 
1049   fclose(fid);
1050 
1051   %%%%%%%%%%   Create for each column pair the data object   %%%%%%%%%%
1052   if isempty(use_fs)
1053 
1054     %%%%%%%%%%   The numbers in columns must be straight   %%%%%%%%%%
1055     if mod(length(columns),2) ~= 0
1056       error('### the numbers in columns must be straight');
1057     end
1058 
1059     for lauf = 1:length(columns)/2
1060 
1061       data_x_axes = f_data(:, columns(lauf*2-1));
1062       data_y_axes = f_data(:, columns(lauf*2));
1063 
1064       %% create data object corresponding to the parameter list
1065       ao_data = [];
1066       switch data_type
1067         case 'tsdata'
1068           ao_data = tsdata( data_x_axes, data_y_axes);
1069         case 'fsdata'
1070           ao_data = fsdata( data_x_axes, data_y_axes);
1071         case 'cdata'
1072           error ('### please code me up')
1073         case 'xydata'
1074           ao_data = xydata( data_x_axes, data_y_axes);
1075         otherwise
1076           error('### unknown data type ''%s''', data_type);
1077       end
1078       ao_data.name = sprintf('f_name_%02d', lauf);
1079       ao_data.xunits = xunits;
1080       ao_data.yunits = yunits;
1081 
1082       aa = init_ao;
1083 
1084       aa.name = sprintf('f_name_%02d', lauf);
1085       aa.data = ao_data;
1086       aa.hist = history(ALGONAME, VERSION, pl);
1087 
1088       %% Set the description fron the parameter list or from the file
1089       description_pl = find(pl, 'description');
1090       if ~isempty(description_pl)
1091         aa.description = description_pl;
1092       end
1093 
1094       a = [a aa];
1095 
1096     end
1097 
1098   %%%%%%%%%%   Create for each column AND fs a data object   %%%%%%%%%%
1099   else % isempty(use_fs)
1100 
1101     for lauf = 1:length(columns)
1102 
1103       data_y_axes = f_data(:, columns(lauf));
1104 
1105       %% create data object corresponding to the parameter list
1106       ao_data = [];
1107       switch data_type
1108         case 'tsdata'
1109           ao_data = tsdata(data_y_axes, use_fs);
1110         case 'fsdata'
1111           ao_data = fsdata(data_y_axes, use_fs);
1112         case 'cdata'
1113           error ('### please code me up')
1114         case 'xydata'
1115           error ('### please code me up')
1116         otherwise
1117           error('### unknown data type ''%s''', data_type);
1118       end
1119       ao_data.name = sprintf('f_name_%02d', lauf);
1120       ao_data.xunits = xunits;
1121       ao_data.yunits = yunits;
1122 
1123       aa      = init_ao;
1124       aa.name = sprintf('f_name_%02d', lauf);
1125       aa.data = ao_data;
1126       aa.hist = history(ALGONAME, VERSION, pl);
1127 
1128       %% Set the description fron the parameter list or from the file
1129       description_pl = find(pl, 'description');
1130       if ~isempty(description_pl)
1131         aa.description = description_pl;
1132       end
1133 
1134       a = [a aa];
1135 
1136     end
1137 
1138   end
1139 
1140   %%%%%%%%%%   set fields of the data object from the parameter list   %%%%%%%%%%
1141   for ii = 1:length(a)
1142     fields = fieldnames(a(ii).data);
1143     for jj = 1:length(pl.params)
1144       parameter = lower(pl.params(jj));
1145       if ismember(parameter.key, upper(fields))           
1146         if iscell(parameter.val)          
1147           if length(parameter.val) > 1
1148             if length(parameter.val) ~= length(a)
1149               warning([sprintf('The values of the key ''%s'' ', parameter.key) ...
1150                                'have not the same length as the lentgh of '    ...
1151                                'the output. Using the first value!']);
1152               a(ii).data.(lower(parameter.key)) = parameter.val{1};
1153             else
1154               a(ii).data.(lower(parameter.key)) = parameter.val{ii};
1155             end
1156           else
1157             a(ii).data.(lower(parameter.key)) = parameter.val{1};
1158           end
1159         else                    
1160           a(ii).data.(lower(parameter.key)) = parameter.val;
1161         end
1162 
1163       end % is parameter key member of the data object
1164     end % for-loop over all parameter
1165   end % for-loop over all ao's
1166 end
1167 
1168 
1169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1170 %
1171 % FUNCTION:    aoFromSpecWin
1172 %
1173 % DESCRIPTION: Construct an ao from a Spectral window
1174 %
1175 % CALL:        a = aoFromSpecWin(a, win, VERSION, ALGONAME)
1176 %
1177 % PARAMETER:   a:        Initialised analysis object
1178 %              win:      Spectral window object
1179 %              VERSION:  cvs version string
1180 %              ALGONAME: The m-file name (use the mfilename command)
1181 %
1182 % HISTORY:     07-05-2007 Hewitson
1183 %              Creation
1184 %
1185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1186 function a = aoFromSpecWin(a, win, VERSION, ALGONAME)
1187 
1188   % Make a cdata object
1189   ts = cdata(win.win);
1190   ts = set(ts, 'name', win.name);
1191 
1192   % Make an analysis object
1193   a.name = win.name;
1194   a.data = ts;
1195   a.hist = history(ALGONAME, VERSION, plist(param('win', win)));
1196 end
1197 
1198 
1199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1200 %
1201 % FUNCTION:    getDefaultPlist
1202 %
1203 % DESCRIPTION: Default Parameter Lists
1204 %
1205 % CALL:        out = getDefaultPlist(set-string)
1206 %
1207 % PARAMETER:   set-string: A string which defines the default parameter list.
1208 %
1209 % HISTORY:     07-05-2007 Hewitson
1210 %              Creation
1211 %
1212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1213 function out = getDefaultPlist(varargin)
1214 
1215   % list of available parameter sets
1216   sets = {'From XML file', 'From ASCII file',...
1217     'Function', 'Values',...
1218     'Time-series Function', 'Frequency-series Function', ...
1219     'From Window', 'Waveform', 'From Polynomial', 'From Repository',...
1220     'From Plist'};
1221 
1222   if nargin == 0
1223     out = sets;
1224     return
1225   end
1226 
1227   set = varargin{1};
1228 
1229   switch set
1230     case 'From Repository'
1231       out = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []);
1232     case 'From XML file'
1233       out = plist('filename', 'foo.xml');
1234     case 'From ASCII file'
1235       out = plist('filename', 'foo.txt',...
1236         'type', 'tsdata',...
1237         'columns', [1 2],...
1238         'num_columns', 10,...
1239         't0', time(0),...
1240         'comment_char', '%');
1241     case 'Function'
1242       out = plist('fcn', 'randn(100,1)');
1243     case 'Values'
1244       out = plist('vals', [1 2 3], 'N', 1);
1245     case 'Time-series Function'
1246       out = plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 100, 't0', time(0));
1247     case 'Frequency-series Function'
1248       out = plist('fsfcn', '1./f', 'f1', 1e-9, 'f2', 100, 'nf', 1000, 'scale', 'log', 'f', []);
1249     case 'From Window'
1250       out = plist('win', specwin('Hanning', 100));
1251     case 'From Polynomial'
1252       out = plist('polyval', [-1e-4 .02 -1 -1], 'Nsecs', 100, 'fs', 10);
1253     case 'From Plist'
1254       out = plist('Plist', plist);
1255     case 'Waveform'
1256       out = plist('waveform', 'sine wave',...
1257         'f', 1.23,...
1258         'phi', 0,...
1259         'fs', 10,...
1260         'nsecs', 10,...
1261         't0', time(0));
1262     otherwise
1263       out = plist();
1264   end
1265 
1266 end
1267 % END
1268 
1269 end

Generated on Fri 07-Mar-2008 15:46:43 by m2html © 2003