function [month,day] = day2mon(year,daysinyear)

%
% Format: [month,day] = day2mon(year, daysinyear)
% The function calculates month and day based on year and yearindays
%

% $Log: day2mon.m,v $
% Revision 1.1  2000/01/12 18:51:14  kwoklin
% Second checkup.  klee
%

% $Id: day2mon.m,v 1.1 2000/01/12 18:51:14 kwoklin Exp $
% klee 11/30/99

if isleap(year)
  monthlastday = [31 60 91 121 152 182 213 244 274 305 335 400];
else
  monthlastday = [31 59 90 120 151 181 212 243 273 304 334 400];
end

month = [];  day = [];
tmp = find(daysinyear <= monthlastday);
month = tmp(1);
if month == 1
  day = daysinyear;
else
  day = daysinyear - monthlastday(tmp(1)-1) + 1;
end
return