function [mastertime,data1out,data2out,data3out,tiltxout,tiltyout,depthout] = OCRaligntime(time1master,time2,time3,auxtime,data1in,data2in,data3in,tiltxin,tiltyin,depthin)

%Linearly interpolate 3 radiometers, tiltx, tilty, and depth data to a common time
%axis.  Profiler tilt and depth data are collected at higher
%time-resolution and could be bin-averaged to the radiometer
%time vector, but this is not implemented here.

%Inputs:  All time vectors should be in Matlab datenum format
%time1master = time vector of "master" sensor (usually Ed,ref)
%time2, time3 = time vectors for other radiometers
%auxtime = auxiliary sensor time vector
%data1in,data2in,data3in = radiometer data (dimension = time x wavelength)
%         corresponding to time1master,time2,time3
%tiltxin, tiltyin = tilt sensor data (dimension = auxtime x 1)
%depthin = profiler depth.  If not present (eg HyperSAS), input empty array ([])

%Avoid interpolating outside measurement time range of master radiometer
masterfirst = find(and(time1master>time2(1),time1master>time3(1)),1,'first');
masterlast = find(and(time1master<time2(length(time2)),time1master<time3(length(time3))),1,'last');
mastertime = time1master(masterfirst:masterlast);

data1out = data1in(masterfirst:masterlast,:);

%Linearly interpolate radiometer and tilt data to master time vector
data2out = interp1(time2,data2in,mastertime,'linear');
data3out = interp1(time3,data3in,mastertime,'linear');
tiltxout = interp1(auxtime,tiltxin,mastertime,'linear');
tiltyout = interp1(auxtime,tiltyin,mastertime,'linear');

%If present, interpolate depth to new time vector
if ~isempty(depthin);
    depthout = interp1(auxtime,depthin,mastertime,'linear');
else
    depthout = [];
end;
