function ydays = cyday(year,month,day)

%
% Format: ydays = cyday(year, month, day)
% The function calculates yeardays based on year, month and day
% Note, it gives 0 for the first day of a year.
%

% $Log$

% $Id$
% klee 08/12/99

monthday1 = [31;28;31;30;31;30;31;31;30;31;30;31];
monthday2 = [31;29;31;30;31;30;31;31;30;31;30;31];

ydays = 0;
if ~isleap(year) 
  for i = 1:month-1
    ydays = ydays + monthday1(i);
  end
else
  for i = 1:month-1
    ydays = ydays + monthday2(i);
  end
end

ydays = ydays + day - 1;

return