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)

 VERSION:     $Id: join.html,v 1.2 2007/07/10 05:37:08 hewitson Exp $

 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.

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

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

 HISTORY: 03-06-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = join(varargin)
0002 % JOIN multiple AOs into a single AO.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: JOIN multiple AOs into a single AO.
0007 %              If any two AOs overlap, then the values from the first appear
0008 %              in the output AO.
0009 %
0010 % CALL:        b = join(a1,a2,pl)
0011 %
0012 % VERSION:     $Id: join.html,v 1.2 2007/07/10 05:37:08 hewitson Exp $
0013 %
0014 % REMARK:      Input AOs should be of the same type; if not, only AOs of the
0015 %              type of the first input AO will be joined together to produce
0016 %              the output.
0017 %
0018 % The following call returns a parameter list object that contains the
0019 % default parameter values:
0020 %
0021 % >> pl = join(ao, 'Params')
0022 %
0023 % HISTORY: 03-06-07 M Hewitson
0024 %             Creation
0025 %
0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0027 
0028 ALGONAME = mfilename;
0029 VERSION  = '$Id: join.html,v 1.2 2007/07/10 05:37:08 hewitson Exp $';
0030 
0031 %% Check if this is a call for parameters
0032 if nargin == 2
0033   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0034     in = char(varargin{2});
0035     if strcmp(in, 'Params')
0036       varargout{1} = getDefaultPL();
0037       return
0038     end
0039   end
0040 end
0041 
0042 
0043 %% capture input variable names
0044 invars = {};
0045 as     = [];
0046 ps     = [];
0047 for j=1:nargin
0048   invars = [invars cellstr(inputname(j))];
0049   if isa(varargin{j}, 'ao')
0050     as = [as varargin{j}];
0051   end
0052   if isa(varargin{j}, 'plist')
0053     ps = [ps varargin{j}];
0054   end
0055 end
0056 
0057 % check plist
0058 if isempty(ps)
0059   pl = getDefaultPL();
0060 else
0061   pl = combine(ps, getDefaultPL);
0062 end
0063 
0064 %----------------------------------------------
0065 % Get data type from the first AO
0066 a     = as(1).data;
0067 dinfo = whos('a');
0068 dtype = dinfo.class;
0069 
0070 %----------------------------------------------
0071 % Go through each AO and collect the data of type 'dtype'
0072 
0073 na     = length(as);
0074 histin = [];
0075 xo     = [];
0076 yo     = [];
0077 fs     = -1;
0078 dname  = [];
0079 aname  = [];
0080 xunits = '';
0081 yunits = '';
0082 
0083 % Compute time offset for tsdata objects
0084 % to avoid rounding errors later
0085 Toff = getToff(as);
0086 
0087 % loop over AOs
0088 for j=1:na
0089 
0090   a = as(j);
0091 
0092   % Only get the data type we want
0093   if isa(a.data, dtype)
0094 
0095     switch dtype
0096       case 'tsdata'
0097 
0098         % here we concatonate time-series
0099         [x,y] = get_xy_axis(a.data);
0100         t0 = ltpda_utc2gps(a.data.t0) - Toff;
0101 
0102         % make proper time vector
0103         x = x + t0;
0104 
0105         % only add samples past the end of existing
0106         if isempty(xo)
0107           yo = y;
0108           xo = x;
0109         else
0110           idx = [find(x > max(xo)) find(x < min(xo))];
0111           xo = [xo;x(idx)];
0112           yo = [yo;y(idx)];
0113         end
0114 
0115         % store fs
0116         if fs>0 && a.data.fs ~= fs
0117           warning('!!! Data has different sample rates !!!');
0118         end
0119         fs = a.data.fs;
0120 
0121         % store xunits
0122         if ~strcmp(xunits, a.data.xunits) && ~isempty(xunits)
0123           warning('!!! Data has different X units !!!');
0124         end
0125         xunits = a.data.xunits;
0126 
0127         % store yunits
0128         if ~strcmp(yunits, a.data.yunits) && ~isempty(yunits)
0129           warning('!!! Data has different Y units !!!');
0130         end
0131         yunits = a.data.yunits;
0132 
0133       case 'fsdata'
0134         error('### I only work with time-series data at the moment.');
0135       case 'xydata'
0136         error('### I only work with time-series data at the moment.');
0137       case 'cdata'
0138         error('### I only work with time-series data at the moment.');
0139       otherwise
0140         error('### Unknown data type');
0141     end
0142 
0143     % Collect this input history
0144     histin = [histin a.hist];
0145 
0146     % Collect names, invars
0147     dname = [dname ',' a.data.name];
0148     if isempty(invars{j})
0149       n = a.name;
0150     else
0151       n = invars{j};
0152     end
0153     aname = [aname ',' n];
0154 
0155   else
0156     warning('!!! Ignoring AO input with data type %s', dtype);
0157   end
0158 
0159 end
0160 % Tidy up names
0161 dname = dname(2:end);
0162 aname = aname(2:end);
0163 
0164 %----------------------------------------------
0165 % Now sort output vectors
0166 [xos, idx] = sort(xo);
0167 yos = yo(idx);
0168 
0169 %% Build output data object
0170 switch dtype
0171   case 'tsdata'
0172 
0173     % get t0
0174     t0  = xos(1);
0175     xos = xos - t0;
0176     data = tsdata(xos, yos);
0177     data = set(data, 't0', ltpda_gps2utc(Toff+t0));
0178     data = set(data, 'name', dname);
0179     data = set(data, 'xunits', xunits);
0180     data = set(data, 'yunits', yunits);
0181 
0182   case 'fsdata'
0183 
0184   case 'xydata'
0185 
0186   case 'cdata'
0187 
0188 end
0189 
0190 %----------------------------------------------
0191 % Build output AO
0192 
0193 h = history(ALGONAME, VERSION, pl, histin);
0194 h = set(h, 'invars', invars);
0195 a = ao(data, h);
0196 
0197 %----------------------------------------------
0198 % set output
0199 
0200 varargout{1} = a;
0201 
0202 
0203 %--------------------------------------------------------------------------
0204 % Get Offset of this set of time-vectors
0205 function Toff = getToff(as)
0206 
0207 Toff = 1e20;
0208 for j=1:length(as)
0209   if isa(as(j).data, 'tsdata')
0210     t0 = ltpda_utc2gps(as(j).data.t0);
0211     if t0 < Toff
0212       Toff = t0;
0213     end
0214   end
0215 end
0216 
0217 %--------------------------------------------------------------------------
0218 % Get default params
0219 function plo = getDefaultPL()
0220 
0221 disp('* creating default plist...');
0222 plo = plist();
0223 disp('* done.');
0224 
0225 
0226 
0227 
0228 
0229 % END

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