%%Calculates the day number given a month, day, and year
%Gwyneth Hughes Jan. 30 2008

function day_num= day_calc(dates)

%%%%%
%Input an n x 3 file with columns = month, day, year
%Output a n x 1 file of day numbers

months=[31 28 31 30 31 30 31 31 30 31 30 31];
months_leap=[31 29 31 30 31 30 31 31 30 31 30 31];

for i=1:size(dates,1)
    if mod(dates(i,3),4)==0
        m=sum(months_leap(1:dates(i,1)-1));
        day_num(i)=m + dates(i,2);
    else
        m=sum(months(1:dates(i,1)-1));
        day_num(i)=m + dates(i,2);
    end;
    day_num=day_num + (dates(i,3)-2005)*365;
    if ((dates(i,3)-2006)>3) | ((dates(i,3)-2006)>3 & dates(i,2)>2) 
        day_num=day_num+1;%Account for the leap year in 2008
    end
end
day_num=day_num';