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