function [month, day] = jul2day(julday, year)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% function [month, day] = jul2day(julday, year)
%%%
%%% jul2day takes a julian day and optional year
%%% and calculates the month and day. note the importance
%%% of the year in case of leap years.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if length(year)~= length(julday)
disp('Input variables must be the same length');
return
end
for i = 1:length(julday)
if rem(year(i),4)~=0,
sum_days = [31 59 90 120 151 181 212 243 273 304 334 366];
else
sum_days = [31 60 91 121 152 182 213 244 274 305 335 366];
end
month(i) = find(sum_days >= julday(i), 1);
if month == 1,
day(i) = julday(i);
else
day(i) = (julday(i) - sum_days(month(i)-1));
end
end
day = day';
month = month';