%% daynum.m calculates the day number for the given day, 
%% month and year.
%%
%% Author: Phillip A. Webb
%% Last updated: June 9 2004                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
%%

function dno=daynum(day,month,year)

% day = day matrix
% month = month matrix
% year = year matrix
% dno = day number

if size(day,1)==1;
 mv=[0 31 59 90 120 151 181 212 243 273 304 334];                               %days in each month (non-leap year)     
else
 mv=[0 31 59 90 120 151 181 212 243 273 304 334]';                              %days in each month (non-leap year)     
end 
dno=day+mv(month);                                                              %calculate day number (non-leap year)                                                      
ly=(month>2)&(rem(year,400)==0 | (rem(year,4)==0 & rem(year,100)~=0));          %if leap year and March or later
dno=dno+ly;                                                                     %update leap year day number

