%% daynum4.m calculates the number of days between the two
%% given day numbers and years.
%% NOTE: scalar inputs only.
%%

function dc=daynum4(dno,year,dnon,yearn)

% dno = original day number
% year = original year number
% dnon = new day number
% yearn = new year number
%
% dc = number of days to change by 

%Determine if new day number and year before or after previous day number and year
dat=year*1e3+dno;
datn=yearn*1e3+dnon;
if dat<datn
 dt=1;
else
 dt=-1;
end

%Loop through daynum31, advancing by dt until new day number and year reached
dc=0;
dnoi=dno;
yeari=year;
while dnoi~=dnon | yeari~=yearn
 [dnoi,yeari]=daynum31(dnoi,yeari,dt);
 dc=dc+dt; 
end





