|%Function to compute date in a year from columns 39 and 40 from the .dat
%file (read using tt2mat). User must input columns 39 and 40 as an nx2
%matrix, together with the year. Output is the date number in standard
% function realdatenum = datenumfromdata(year,data3940);
% year is the year of the very first measurement
% data3940 is a nx2 matrix with the first column equal to column 39
% and the second column equal to column 40 from the .dat file (e.g.
%OAM, October 30, 2008.
function realdatenum = datenumfromdata(year,data3940)
error(‘There must be 2 input arguments: year and a matrix with 2 columns’)
error(‘There must be 2 columns in the input matrix data3940’)
%compute days, hours, minutes, seconds
days = fix(data3940(:,1)/100);
hours = data3940(:,1)-100*days;
minutes = fix(data3940(:,2)/100);
seconds = data3940(:,2)-100*minutes;
years = year*ones(size(data3940,1),1);%creat a vector with the initial year
NewYear=find(diff(days)<0);%find negative differences in daynumber (indicate deployment over new year)
if ~isempty(NewYear);%If we have a new year deployment…
years(NewYear+1:end)=year+1;%…the year after new year is one higher than the inital year (we assume that the deployment doesn’t span more than one new year)!
realdatenum = datenum(years,1,days,hours,minutes,seconds);