0001
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 function varargout = join(varargin)
0028
0029
0030 if utils.helper.isinfocall(varargin{:})
0031 varargout{1} = getInfo(varargin{3});
0032 return
0033 end
0034
0035 if nargout == 0
0036 error('### join cannot be used as a modifier. Please give an output variable.');
0037 end
0038
0039 import utils.const.*
0040 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0041
0042
0043 in_names = cell(size(varargin));
0044 for ii = 1:nargin,in_names{ii} = inputname(ii);end
0045
0046
0047 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0048
0049
0050
0051 dtype = class(as(1).data);
0052
0053
0054
0055
0056 histin = [];
0057 xo = [];
0058 yo = [];
0059 fs = -1;
0060 dname = '';
0061 aname = '';
0062 xunits = as(1).data.xunits;
0063 yunits = as(1).data.yunits;
0064
0065
0066
0067
0068 Toff = getToff(as);
0069 fsDifferent = false;
0070
0071 for j=1:numel(as)
0072
0073 if isa(as(j).data, dtype)
0074 switch dtype
0075 case 'tsdata'
0076
0077 t0 = (as(j).data.t0.utc_epoch_milli - Toff)/1000;
0078
0079 x = as(j).data.getX + t0;
0080
0081 if isempty(xo)
0082 yo = as(j).data.getY;
0083 xo = x;
0084 else
0085 idxPost = find(x > max(xo));
0086 idxPre = find(x < min(xo));
0087 xo = [x(idxPre); xo; x(idxPost)];
0088 yo = [as(j).data.getY(idxPre); yo; as(j).data.getY(idxPost)];
0089 end
0090
0091
0092 if fs>0 && as(j).data.fs ~= fs
0093 error('!!! Data has different sample rates !!!');
0094 end
0095 fs = as(j).data.fs;
0096
0097
0098 if xunits ~= as(j).data.xunits
0099 error('!!! Data has different X units !!!');
0100 end
0101 xunits = as(j).data.xunits;
0102
0103
0104 if yunits ~= as(j).data.yunits
0105 error('!!! Data has different Y units !!!');
0106 end
0107 yunits = as(j).data.yunits;
0108
0109 case 'fsdata'
0110 error('### I only work with time-series data at the moment.');
0111 case 'xydata'
0112 error('### I only work with time-series data at the moment.');
0113 case 'cdata'
0114 error('### I only work with time-series data at the moment.');
0115 otherwise
0116 error('### Unknown data type');
0117 end
0118
0119 histin = [histin as(j).hist];
0120
0121 if ~isempty(aname)
0122 if ~strcmp(aname, as(j).name)
0123 aname = [aname ',' as(j).name];
0124 end
0125 else
0126 aname = as(j).name;
0127 end
0128 else
0129 warning('!!! Ignoring AO input with data type %s', dtype);
0130 end
0131 end
0132
0133 dname = dname(2:end);
0134
0135
0136
0137 [xos, idx] = sort(xo);
0138 yos = yo(idx);
0139
0140
0141 switch dtype
0142 case 'tsdata'
0143
0144 t0 = xos(1);
0145 xos = xos - t0;
0146 data = tsdata(xos, yos, fs);
0147 data.setT0((Toff+t0*1000));
0148 data.setXunits(xunits);
0149 data.setYunits(yunits);
0150 case 'fsdata'
0151 case 'xydata'
0152 case 'cdata'
0153 end
0154
0155
0156
0157 a = ao(data);
0158 a.setName(aname, 'internal');
0159
0160 a.addHistory(getInfo, plist, ao_invars, histin);
0161
0162
0163
0164 varargout{1} = a;
0165 end
0166
0167
0168
0169
0170 function ii = getInfo(varargin)
0171 if nargin == 1 && strcmpi(varargin{1}, 'None')
0172 sets = {};
0173 pl = [];
0174 else
0175 sets = {'Default'};
0176 pl = getDefaultPlist;
0177 end
0178
0179 ii = minfo(mfilename, 'ao', '', utils.const.categories.helper, '$Id: join.m,v 1.24 2008/09/05 11:05:29 ingo Exp $', sets, pl);
0180 end
0181
0182
0183
0184
0185 function pl = getDefaultPlist()
0186 pl = plist();
0187 end
0188
0189
0190
0191
0192 function Toff = getToff(as)
0193 Toff = 1e20;
0194 for j=1:length(as)
0195 if isa(as(j).data, 'tsdata')
0196 t0 = as(j).data.t0.utc_epoch_milli;
0197 if t0 < Toff
0198 Toff = t0;
0199 end
0200 end
0201 end
0202 end
0203