function [y, mo, d, h, m, s] = calendar_day(year,day) %function [y, mo, d, h, m, s] = calendar_day(year,day) % % Example input: (1999, 43.5) % Example output: [1999, 2, 12, 12, 0, 0] % % Converts day of year to calendar day eom = [0 31 28 31 30 31 30 31 31 30 31 30 31]; if(year/4 == round(year/4)) % leap year eom(3) = 29; end y = year; dateleft = day; [I,J] = size(dateleft); eom = cumsum(eom); for i = 1:I for j = 1:J mo(i,j) = max(find((dateleft(i,j)-eom)>0)); end end eomM = eom(mo); if(size(eomM) ~= size(dateleft)) dateleft = dateleft-eomM'; d = floor(dateleft); else dateleft = dateleft-eomM; d = floor(dateleft); end dateleft = (dateleft - d)*24; h = floor(dateleft); dateleft = (dateleft - h)*60; m = floor(dateleft); dateleft = (dateleft - m)*60; s = dateleft;