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] = sort(time_in, 'ascend');
d = data_in(si);

% Assure time vector either increases or decreases monotonically
t = monotonic(t); 

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

data_out = d;
time_out = t;

end