Home > classes > @ao > join.m

join

PURPOSE ^

JOIN multiple AOs into a single AO.

SYNOPSIS ^

function varargout = join(varargin)

DESCRIPTION ^

 JOIN multiple AOs into a single AO.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: JOIN multiple AOs into a single AO.
              If any two AOs overlap, then the values from the first appear
              in the output AO.

 CALL:        b = join(a1,a2,pl)

 REMARK:      Input AOs should be of the same type; if not, only AOs of the
              type of the first input AO will be joined together to produce
              the output.

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('join')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('join', 'None')

 VERSION:     $Id: join.m,v 1.24 2008/09/05 11:05:29 ingo Exp $

 HISTORY: 03-06-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % JOIN multiple AOs into a single AO.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: JOIN multiple AOs into a single AO.
0005 %              If any two AOs overlap, then the values from the first appear
0006 %              in the output AO.
0007 %
0008 % CALL:        b = join(a1,a2,pl)
0009 %
0010 % REMARK:      Input AOs should be of the same type; if not, only AOs of the
0011 %              type of the first input AO will be joined together to produce
0012 %              the output.
0013 %
0014 % M-FILE INFO: Get information about this methods by calling
0015 %              >> ao.getInfo('join')
0016 %
0017 %              Get information about a specified set-plist by calling:
0018 %              >> ao.getInfo('join', 'None')
0019 %
0020 % VERSION:     $Id: join.m,v 1.24 2008/09/05 11:05:29 ingo Exp $
0021 %
0022 % HISTORY: 03-06-07 M Hewitson
0023 %             Creation
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 
0027 function varargout = join(varargin)
0028 
0029   % Check if this is a call for parameters
0030   if utils.helper.isinfocall(varargin{:})
0031     varargout{1} = getInfo(varargin{3});
0032     return
0033   end
0034 
0035   if nargout == 0
0036     error('### join cannot be used as a modifier. Please give an output variable.');
0037   end
0038 
0039   import utils.const.*
0040   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0041   
0042   % Collect input variable names
0043   in_names = cell(size(varargin));
0044   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0045 
0046   % Collect all AOs
0047   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0048 
0049   %----------------------------------------------
0050   % Get data type from the first AO
0051   dtype = class(as(1).data);
0052 
0053   %----------------------------------------------
0054   % Go through each AO and collect the data of type 'dtype'
0055 
0056   histin = [];
0057   xo     = [];
0058   yo     = [];
0059   fs     = -1;
0060   dname  = '';
0061   aname  = '';
0062   xunits = as(1).data.xunits;
0063   yunits = as(1).data.yunits;
0064 
0065   % Compute time offset for tsdata objects
0066   % to avoid rounding errors later
0067 
0068   Toff = getToff(as);
0069   fsDifferent = false;
0070   % loop over AOs
0071   for j=1:numel(as)
0072     % Only get the data type we want
0073     if isa(as(j).data, dtype)
0074       switch dtype
0075         case 'tsdata'
0076           % here we concatonate time-series
0077           t0 = (as(j).data.t0.utc_epoch_milli - Toff)/1000;
0078           % make proper time vector
0079           x = as(j).data.getX + t0;
0080           % only add samples past the end of existing
0081           if isempty(xo)
0082             yo = as(j).data.getY;
0083             xo = x;
0084           else
0085             idxPost = find(x > max(xo));
0086             idxPre  = find(x < min(xo));
0087             xo = [x(idxPre); xo; x(idxPost)];
0088             yo = [as(j).data.getY(idxPre); yo; as(j).data.getY(idxPost)];
0089           end
0090 
0091           % store fs
0092           if fs>0 && as(j).data.fs ~= fs
0093             error('!!! Data has different sample rates !!!');
0094           end
0095           fs = as(j).data.fs;
0096 
0097           % store xunits
0098           if xunits ~= as(j).data.xunits
0099             error('!!! Data has different X units !!!');
0100           end
0101           xunits = as(j).data.xunits;
0102 
0103           % store yunits
0104           if yunits ~= as(j).data.yunits
0105             error('!!! Data has different Y units !!!');
0106           end
0107           yunits = as(j).data.yunits;
0108 
0109         case 'fsdata'
0110           error('### I only work with time-series data at the moment.');
0111         case 'xydata'
0112           error('### I only work with time-series data at the moment.');
0113         case 'cdata'
0114           error('### I only work with time-series data at the moment.');
0115         otherwise
0116           error('### Unknown data type');
0117       end
0118       % Collect this input history
0119       histin = [histin as(j).hist];
0120       % Collect names, invars
0121       if ~isempty(aname)
0122         if ~strcmp(aname, as(j).name)
0123           aname = [aname ',' as(j).name];
0124         end
0125       else
0126         aname = as(j).name;
0127       end
0128     else
0129       warning('!!! Ignoring AO input with data type %s', dtype);
0130     end
0131   end
0132   % Tidy up names
0133   dname = dname(2:end);
0134 
0135   %----------------------------------------------
0136   % Now sort output vectors
0137   [xos, idx] = sort(xo);
0138   yos = yo(idx);
0139 
0140   %% Build output data object
0141   switch dtype
0142     case 'tsdata'
0143       % get t0
0144       t0  = xos(1);
0145       xos = xos - t0;
0146       data = tsdata(xos, yos, fs);
0147       data.setT0((Toff+t0*1000));
0148       data.setXunits(xunits);
0149       data.setYunits(yunits);
0150     case 'fsdata'
0151     case 'xydata'
0152     case 'cdata'
0153   end
0154 
0155   %----------------------------------------------
0156   % Build output AO
0157   a = ao(data);
0158   a.setName(aname, 'internal');
0159   % add history
0160   a.addHistory(getInfo, plist, ao_invars, histin);
0161 
0162   %----------------------------------------------
0163   % set output
0164   varargout{1} = a;
0165 end
0166 
0167 %--------------------------------------------------------------------------
0168 % Get Info Object
0169 %--------------------------------------------------------------------------
0170 function ii = getInfo(varargin)
0171   if nargin == 1 && strcmpi(varargin{1}, 'None')
0172     sets = {};
0173     pl   = [];
0174   else
0175     sets = {'Default'};
0176     pl   = getDefaultPlist;
0177   end
0178   % Build info object
0179   ii = minfo(mfilename, 'ao', '', utils.const.categories.helper, '$Id: join.m,v 1.24 2008/09/05 11:05:29 ingo Exp $', sets, pl);
0180 end
0181 
0182 %--------------------------------------------------------------------------
0183 % Get Default Plist
0184 %--------------------------------------------------------------------------
0185 function pl = getDefaultPlist()
0186   pl = plist();
0187 end
0188 
0189 %--------------------------------------------------------------------------
0190 % Get Offset of this set of time-vectors
0191 %--------------------------------------------------------------------------
0192 function Toff = getToff(as)
0193   Toff = 1e20;
0194   for j=1:length(as)
0195     if isa(as(j).data, 'tsdata')
0196       t0 = as(j).data.t0.utc_epoch_milli;
0197       if t0 < Toff
0198         Toff = t0;
0199       end
0200     end
0201   end
0202 end
0203

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003