function [ time_out, data_out ] = fixTimeseries( time_in, data_in )

% Fix non-monotonic time stamps in LRAUV datasets. 
% Returnes corrected time stamp and value vectors.

% take care of unsorted time vector and match data
[t, si] = unique(time_in, 'sorted');
d = data_in(si);

% Fill in NaN
t(isnan(t)) = interp1(find(~isnan(t)), t(~isnan(t)), find(isnan(t)),'PCHIP');

data_out = d;
time_out = t;

end