-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdays2mdh.m
73 lines (65 loc) · 2.3 KB
/
days2mdh.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% ------------------------------------------------------------------------------
%
% function days2mdh
%
% this function converts the day of the year, days, to the equivalent month
% day, hour, minute and second.
%
% author : david vallado 719-573-2600 22 jun 2002
%
% revisions
% -
%
% inputs description range / units
% year - year 1900 .. 2100
% days - julian day of the year 0.0 .. 366.0
%
% outputs :
% mon - month 1 .. 12
% day - day 1 .. 28,29,30,31
% hr - hour 0 .. 23
% minute - minute 0 .. 59
% sec - second 0.0 .. 59.999
%
% locals :
% dayofyr - day of year
% temp - temporary extended values
% inttemp - temporary integer value
% i - index
% lmonth(12) - integer array containing the number of days per month
%
% coupling :
% none.
%
% [mon,day,hr,minute,sec] = days2mdh ( year,days);
% -----------------------------------------------------------------------------
function [mon,day,hr,minute,sec] = days2mdh ( year,days);
% --------------- set up array of days in month --------------
for i= 1 : 12
lmonth(i) = 31;
if i == 2
lmonth(i)= 28;
end;
if i == 4 | i == 6 | i == 9 | i == 11
lmonth(i)= 30;
end;
end
dayofyr= floor(days );
% ----------------- find month and day of month ---------------
if rem(year-1900,4) == 0
lmonth(2)= 29;
end
i= 1;
inttemp= 0;
while ( dayofyr > inttemp + lmonth(i) ) & ( i < 12 )
inttemp= inttemp + lmonth(i);
i= i+1;
end
mon= i;
day= dayofyr - inttemp;
% ----------------- find hours minutes and seconds ------------
temp= (days - dayofyr )*24.0;
hr = fix( temp );
temp= (temp-hr) * 60.0;
minute = fix( temp );
sec = (temp-minute) * 60.0;