function [masterwl,data1out,data2out,data3out] = OCRalignwl(wl1master,wl2,wl3,data1in,data2in,data3in)

%Linearly interpolate 3 radiometers to a common wavelength
%axis.  

%Inputs:  All wavelength vectors should be pre-loaded from OCRstuff.mat
%wl1master = wavelength vector of "master" sensor (usually Ed,ref)
%wl2, wl3 = wavelength vectors for other radiometers
%data1in,data2in,data3in = radiometer data (dimension = time x wavelength)
%         corresponding to wl1master,wl2,wl3

%Avoid interpolating outside master sensor's wavelength range 
masterfirst = find(and(wl1master>wl2(1),wl1master>wl3(1)),1,'first');
masterlast = find(and(wl1master<wl2(length(wl2)),wl1master<wl3(length(wl3))),1,'last');

masterwl = wl1master(masterfirst:masterlast);

data1out = data1in(:,masterfirst:masterlast);

%Linearly interpolate all sensors to the master wavelength range
data2out = interp1(wl2',data2in',masterwl','linear')';
data3out = interp1(wl3',data3in',masterwl','linear')';