


GREGORIAN Converts digital Julian days to Gregorian calendar dates.
Although formally,
Julian days start and end at noon, here Julian days
start and end at midnight for simplicity.
In this convention, Julian day 2440000 begins at
0000 hours, May 23, 1968.
Usage: [gtime]=gregorian(julian)
julian... input decimal Julian day number
gtime is a six component Gregorian time vector
i.e. gtime=[yyyy mo da hr mi sec]
gtime=[1989 12 6 7 23 23.356]

0001 function [gtime]=gregorian(julian) 0002 %GREGORIAN Converts digital Julian days to Gregorian calendar dates. 0003 % Although formally, 0004 % Julian days start and end at noon, here Julian days 0005 % start and end at midnight for simplicity. 0006 % 0007 % In this convention, Julian day 2440000 begins at 0008 % 0000 hours, May 23, 1968. 0009 % 0010 % Usage: [gtime]=gregorian(julian) 0011 % 0012 % julian... input decimal Julian day number 0013 % 0014 % gtime is a six component Gregorian time vector 0015 % i.e. gtime=[yyyy mo da hr mi sec] 0016 % gtime=[1989 12 6 7 23 23.356] 0017 0018 % yr........ year (e.g., 1979) 0019 % mo........ month (1-12) 0020 % d........ corresponding Gregorian day (1-31) 0021 % h........ decimal hours 0022 % 0023 % calls S2HMS 0024 0025 julian=julian+5.e-9; % kludge to prevent roundoff error on seconds 0026 0027 % if you want Julian Days to start at noon... 0028 % h=rem(julian,1)*24+12; 0029 % i=(h >= 24); 0030 % julian(i)=julian(i)+1; 0031 % h(i)=h(i)-24; 0032 0033 secs=rem(julian,1)*24*3600; 0034 0035 j = floor(julian) - 1721119; 0036 in = 4*j -1; 0037 y = floor(in/146097); 0038 j = in - 146097*y; 0039 in = floor(j/4); 0040 in = 4*in +3; 0041 j = floor(in/1461); 0042 d = floor(((in - 1461*j) +4)/4); 0043 in = 5*d -3; 0044 m = floor(in/153); 0045 d = floor(((in - 153*m) +5)/5); 0046 y = y*100 +j; 0047 mo=m-9; 0048 yr=y+1; 0049 i=(m<10); 0050 mo(i)=m(i)+3; 0051 yr(i)=y(i); 0052 [hour,min,sec]=s2hms(secs); 0053 gtime=[yr(:) mo(:) d(:) hour(:) min(:) sec(:)];