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.

 If any two AOs overlap, then the values from the first appear in the
 output AO.

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

 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 Hewitson 03-06-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003