NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/timefun/gregorian.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function [gtime]=gregorian(julian)
2 %GREGORIAN  Converts Julian day numbers to corresponding
3 %       Gregorian calendar dates.  Although formally,
4 %       Julian days start and end at noon, here Julian days
5 %       start and end at midnight for simplicity.
6 %     
7 %       In this convention, Julian day 2440000 begins at
8 %       0000 hours, May 23, 1968.
9 %
10 %     Usage: [gtime]=gregorian(julian)
11 %
12 %        julian... input decimal Julian day number
13 %
14 %        gtime is a six component Gregorian time vector
15 %          i.e.   gtime=[yyyy mo da hr mi sec]
16 %                 gtime=[1989 12  6  7 23 23.356]
17  
18 %        yr........ year (e.g., 1979)
19 %        mo........ month (1-12)
20 %        d........ corresponding Gregorian day (1-31)
21 %        h........ decimal hours
22 %
23       julian=julian+5.e-9;    % kludge to prevent roundoff error on seconds
24
25 %      if you want Julian Days to start at noon...
26 %      h=rem(julian,1)*24+12;
27 %      i=(h >= 24);
28 %      julian(i)=julian(i)+1;
29 %      h(i)=h(i)-24;
30
31       secs=rem(julian,1)*24*3600;
32
33       j = floor(julian) - 1721119;
34       in = 4*j -1;
35       y = floor(in/146097);
36       j = in - 146097*y;
37       in = floor(j/4);
38       in = 4*in +3;
39       j = floor(in/1461);
40       d = floor(((in - 1461*j) +4)/4);
41       in = 5*d -3;
42       m = floor(in/153);
43       d = floor(((in - 153*m) +5)/5);
44       y = y*100 +j;
45       mo=m-9;
46       yr=y+1;
47       i=(m<10);
48       mo(i)=m(i)+3;
49       yr(i)=y(i);
50       [hour,min,sec]=s2hms(secs);
51       gtime=[yr(:) mo(:) d(:) hour(:) min(:) sec(:)];
Note: See TracBrowser for help on using the browser.