%% daynum3.m calculates the new day number and year, given an
%% initial day number and year. 
%% NOTE: - only works for scalar input
%%

function [dnon,yearn]=daynum3(dno,year,dc)

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

if abs(dc)<365
 [dnon,yearn]=daynum31(dno,year,dc);         %final daynumber and year
elseif dc>=365
 [dnon,yearn]=daynum31(dno,year,365);        %final daynumber and year
 dc=dc-365;
 while dc>0
  dnoq=min(dc,365);
  [dnon,yearn]=daynum31(dnon,yearn,dnoq);    %final daynumber and year
  dc=dc-365;
 end
else 
 [dnon,yearn]=daynum31(dno,year,-365);       %final daynumber and year
 dc=dc+365;
 while dc<0
  dnoq=max(dc,-365);
  [dnon,yearn]=daynum31(dnon,yearn,dnoq);    %final daynumber and year
  dc=dc+365;
 end
end