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