-
Notifications
You must be signed in to change notification settings - Fork 0
/
julian.m
49 lines (45 loc) · 1.52 KB
/
julian.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function [j]=julian(y,m,d,h)
% JULIAN Converts Gregorian calendar dates to corresponding Julian day numbers.
% The formal definition holds that Julian days start and end at
% noon (because astronomers thought it up).
%
% In this convention, Julian day 2440000 began at 1200 hours, May 23, 1968.
%
%
% Usage: [j]=julian(y,m,d,h) or [j]=julian([y m d hour min sec])
% ************************************************************
%
% d.... day (1-31) component of Gregorian date
% m.... month (1-12) component
% y.... year (e.g., 1979) component
% j.... decimal Julian day number
% h.... decimal hours (assumed 0 if absent)
%
% ************************************************************
% $Id: julian.m Mon, 03 Jul 2006 17:16:40 $
% recoded for MATLAB by Rich Signell, 5-15-91
% Hacked by Jim Mansbridge. (Rich Signell had Julian days start
% and end at midnight. In this convention, Julian day 2440000
% began at 0000 hours, May 23, 1968.)
%
if nargin==3,
h=0.;
elseif nargin==1,
h=hms2h(y(:,4),y(:,5),y(:,6));
d=y(:,3);
m=y(:,2);
y=y(:,1);
end
mo=m+9;
yr=y-1;
i=(m>2);
mo(i)=m(i)-3;
yr(i)=y(i);
c = floor(yr/100);
yr = yr - c*100;
j = floor((146097*c)/4) + floor((1461*yr)/4) + ...
floor((153*mo +2)/5) +d +1721119;
% If you want julian days to start and end at noon,
% replace the following line with:
j=j+(h-12)/24;
% j=j+h/24;