function ymdhms = to_date(year_base, dec_day);
%
% function ymdhms = to_date(year_base, dec_day)
% returns ymdhms string equivalent to decimal day arg

% 93/02/10 JR

if nargin ~= 2
  help to_date
  return
end

year_base = 1900 + year_base;
secs = to_sec([year_base 1 1 0 0 0]) + round(dec_day * 86400);
days = secs / 86400;         % days-equivalent
y1   = fix(days / 365.25);   % no. of complete years since year 1, first guess
d1   = y1 * 365 + fix(y1/4) - fix(y1/100) + fix(y1/400);
year = y1 + 1;
if days - d1 >= (365 + (rem(year, 4) == 0) - (rem(year, 100) == 0) + (rem(year, 400) == 0));
  y1 = y1 + 1;
  year = year + 1;
end
days = days - (365 * y1 + fix(y1/4) - fix(y1/100) + fix(y1/400));
   
if rem(year, 4) > 0
  cum_days = [0 31 59 90 120 151 181 212 243 273 304 334 365];
else
  cum_days = [0 31 60 91 121 152 182 213 244 274 305 335 366];
end

month = find(cum_days > days);
month = month(1) - 1;

day = fix(1 + days - cum_days(month));
secs = rem(secs, 86400);

frac = dec_day - fix(dec_day);
hour = fix(frac * 24);
minute = fix(rem(frac * 1440, 60));
second = round(frac * 86400 - hour * 3600 - minute * 60);

ymdhms = [sprintf('%02.0f/%02.0f/%02.0f ', year-1900, month, day) ...
	  sprintf('%02.0f:%02.0f:%02.0f', hour, minute, second)];
