% calculates the Julian day given year, month and day
function [month day] = yd2md(year, yday)
day_tab=[31,28,31,30,31,30,31,31,30,31,30,31; 31,29,31,30,31,30,31,31,30,31,30,31];

leap = (mod(year,4) == 0 && mod(year,100) ~= 0 || mod(year,400) == 0) + 1;

i = 1;

while yday > day_tab(leap,i)
    yday = yday - day_tab(leap,i);
    month = i;
    day = yday;
    i = i + 1;
end

month = i;
day   = yday;
