0001 function varargout = join(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 ALGONAME = mfilename;
0029 VERSION = '$Id: join.m,v 1.11 2007/11/26 14:48:13 ingo Exp $';
0030
0031
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 elseif strcmp(in, 'Version')
0039 varargout{1} = VERSION;
0040 return
0041 end
0042 end
0043 end
0044
0045
0046
0047 in_names = {};
0048 for ii = 1:nargin
0049 in_names{end+1} = inputname(ii);
0050 end
0051
0052 [as, ps, invars] = collect_inputs(varargin, in_names);
0053
0054
0055 if isempty(ps)
0056 pl = getDefaultPL();
0057 else
0058 pl = combine(ps, getDefaultPL);
0059 end
0060
0061
0062
0063 a = as(1).data;
0064 dinfo = whos('a');
0065 dtype = dinfo.class;
0066
0067
0068
0069
0070 histin = [];
0071 xo = [];
0072 yo = [];
0073 fs = -1;
0074 dname = [];
0075 xunits = '';
0076 yunits = '';
0077
0078
0079
0080
0081 Toff = getToff(as);
0082
0083
0084 for j=1:numel(as)
0085
0086 a = as(j);
0087
0088
0089 if isa(a.data, dtype)
0090
0091 switch dtype
0092 case 'tsdata'
0093
0094
0095 [x,y] = get_xy_values(a.data);
0096 t0 = (a.data.t0.utc_epoch_milli - Toff)/1000;
0097
0098
0099 x = x + t0;
0100
0101
0102 if isempty(xo)
0103 yo = y;
0104 xo = x;
0105 else
0106 idxPost = find(x > max(xo));
0107 idxPre = find(x < min(xo));
0108 xo = [x(idxPre);xo;x(idxPost)];
0109 yo = [y(idxPre);yo;y(idxPost)];
0110 end
0111
0112
0113 if fs>0 && a.data.fs ~= fs
0114 warning('!!! Data has different sample rates !!!');
0115 end
0116 fs = a.data.fs;
0117
0118
0119 if ~strcmp(xunits, a.data.xunits) && ~isempty(xunits)
0120 warning('!!! Data has different X units !!!');
0121 end
0122 xunits = a.data.xunits;
0123
0124
0125 if ~strcmp(yunits, a.data.yunits) && ~isempty(yunits)
0126 warning('!!! Data has different Y units !!!');
0127 end
0128 yunits = a.data.yunits;
0129
0130 case 'fsdata'
0131 error('### I only work with time-series data at the moment.');
0132 case 'xydata'
0133 error('### I only work with time-series data at the moment.');
0134 case 'cdata'
0135 error('### I only work with time-series data at the moment.');
0136 otherwise
0137 error('### Unknown data type');
0138 end
0139
0140
0141 histin = [histin a.hist];
0142
0143
0144 dname = [dname ',' a.data.name];
0145
0146 else
0147 warning('!!! Ignoring AO input with data type %s', dtype);
0148 end
0149
0150 end
0151
0152 dname = dname(2:end);
0153
0154
0155
0156 [xos, idx] = sort(xo);
0157 yos = yo(idx);
0158
0159
0160 switch dtype
0161 case 'tsdata'
0162
0163
0164 t0 = xos(1);
0165 xos = xos - t0;
0166 data = tsdata(xos, yos);
0167 data = set(data, 't0', (Toff+t0));
0168 data = set(data, 'name', dname);
0169 data = set(data, 'xunits', xunits);
0170 data = set(data, 'yunits', yunits);
0171
0172 case 'fsdata'
0173
0174 case 'xydata'
0175
0176 case 'cdata'
0177
0178 end
0179
0180
0181
0182
0183 h = history(ALGONAME, VERSION, pl, histin);
0184 h = set(h, 'invars', invars);
0185 a = ao(data, h);
0186
0187
0188
0189
0190 varargout{1} = a;
0191
0192
0193
0194
0195 function Toff = getToff(as)
0196
0197 Toff = 1e20;
0198 for j=1:length(as)
0199 if isa(as(j).data, 'tsdata')
0200 t0 = as(j).data.t0.utc_epoch_milli;
0201 if t0 < Toff
0202 Toff = t0;
0203 end
0204 end
0205 end
0206
0207
0208
0209 function plo = getDefaultPL()
0210
0211 plo = plist();
0212
0213
0214
0215
0216
0217