function [date]= calday(year,jd)
%	Converts decimal Julian day to calendar day.
%
%	function [date] = calday([year|method70],jd)
%	  If the year is given, then jd is less than 365.
%	  If year ='y', then jd is given in method70.
%	    Method70 gives jd as # days since 1/1/70.
%	  date=[yr mo dd hh mm ss];

yrs=[70 71 72 73 74 75 76 77 78 79 ...
    80 81 82 83 84 85 86 87 88 89 ...
    90 91 92 93 94 95 96 97 98 99];

dyr=[   0  365  730 1096 1461 1826 2191 2557 2922 3287 ...
     3652 4018 4383 4748 5113 5479 5844 6209 6574 6940 ...
     7305 7670 8035 8401 8766 9131 9496 9862 10227 10592];

lenmo = [31,28,31,30,31,30,31,31,30,31,30,31];

if isstr(year)
  i= (find((-dyr+jd) > 0));
  yr= yrs(i(length(i)));
  jd= jd - dyr(yr-yrs(1)+1);
else
  yr=year;
end;

djday=jd;
jd=floor(jd);
dhr = (djday-jd)*24;
hh = fix(dhr);
dmn = (dhr-hh)*60;
mm = fix(dmn);
ss = round((dmn-mm)*60);
if ss == 60,
   ss = 0;
   mm = mm+1;
   if(mm == 60),
      mm = 0;
      hh = hh+1;
      if(hh == 24),
         hh = 0;
         jd=jd+1;
      end
   end
end
lenyr=365;
if rem(yr,4) == 0, lenyr= 366; end
if (jd > lenyr),
   jd = jd-lenyr;
   yr = yr+1;
end
if rem(yr,4) == 0, lenmo(2) = 29; end
dd=jd+1;
if (hh == 0 & mm == 0), dd=dd-1; end;
mo = 1;
while dd  > lenmo(mo),
   dd = dd - lenmo(mo);
   mo = mo+1;
end;
date=[yr mo dd hh mm ss];
