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