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

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

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

Initial import of Stark code.

Line 
1 function [j]=julian(y,m,d,h)
2 %JULIAN  Converts Gregorian calendar dates to corresponding
3 %      Julian day numbers.  Although the formal definition
4 %      holds that Julian days start and end at noon, here
5 %      Julian days start and end at midnight.
6 %
7 %    In this convention, Julian day 2440000 began at 0000 hours, May 23, 1968.
8 %
9 %
10 %     Usage: [j]=julian(y,m,d,h)  or  [j]=julian([y m d hour min sec])
11 %     ************************************************************
12 %
13 %        d.... day (1-31) component of Gregorian date
14 %        m.... month (1-12) component
15 %        y.... year (e.g., 1979) component
16 %        j.... decimal Julian day number
17 %        h.... decimal hours (assumed 0 if absent)
18 %
19 %     ************************************************************
20 %     recoded for MATLAB  by Rich Signell, 5-15-91
21 %     vectorized code for when nargin==1 by SMH 9-6-94
22 %
23       if nargin==3,
24         h=0.;
25       elseif nargin==1,
26         h=hms2h(y(:,4),y(:,5),y(:,6));
27         d=y(:,3);
28         m=y(:,2);
29         y=y(:,1);
30       end
31       mo=m+9;
32       yr=y-1;
33       i=(m>2);
34       mo(i)=m(i)-3;
35       yr(i)=y(i);
36       c = floor(yr/100);
37       yr = yr - c*100;
38       j = floor((146097*c)/4) + floor((1461*yr)/4) + ...
39            floor((153*mo +2)/5) +d +1721119;
40
41 %     If you want julian days to start and end at noon,
42 %     replace the following line with:
43 %     j=j+(h-12)/24;
44  
45       j=j+h/24;
46
Note: See TracBrowser for help on using the browser.