-
Notifications
You must be signed in to change notification settings - Fork 10
/
date_after_transfer.m
108 lines (82 loc) · 2.73 KB
/
date_after_transfer.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function date_vec = date_after_transfer(print_out, d, m, y, in_h, in_m, in_s, days)
%% calculates the date of arrival after an interplanetary transfer
%
% Jeremy Penn
% 12/11/17
%
% function date_after_transfer()
%
% Input: o print_out - A string to decide whether to print to screen.
% Leave blank to print-to-screen.
%
if nargin == 0
print_out = 'yes';
%% Inputs
date = input('Input the departure date (dd/mm/yyyy/):\n','s');
split = strsplit(date, '/');
d = str2double(split{1});
m = str2double(split{2});
y = str2double(split{3});
time = input('input the time of departure (HH:MM:SS UT):\n','s');
split_time = strsplit(time, ':');
in_h = str2double(split_time{1});
in_m = str2double(split_time{2});
in_s = str2double(split_time{3});
days = input('Length of transfer (days, use fractions of a day):\n');
end
%% calculate the new date
time_h = in_s/3600 + in_m/60 + in_h;
% convert to total days
if mod(y, 4) == 0
length_of_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
else
length_of_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
end
month_d = 0;
for i = 1:m - 1
month_d = month_d + length_of_month(i);
end
arrive_d = d + month_d + days + time_h/24; % total days
% back convert to dd/mm/yy from total days
while arrive_d > 365
arrive_d = arrive_d - 365;
y = y + 1;
end
mm = 0;
for j = 1:12
if arrive_d <= length_of_month(j)
break
end
arrive_d = arrive_d - length_of_month(j);
mm = mm + 1;
end
if arrive_d - round(arrive_d) ~= 0
remain = arrive_d - floor(arrive_d);
arrive_d = floor(arrive_d);
hr = remain * 24;
if hr - round(hr) ~= 0
h_remain = hr - floor(hr);
hr = floor(hr);
min = h_remain * 60;
if min - round(min) ~= 0
m_remain = min - floor(min);
min = floor(min);
sec = m_remain * 60;
end
else
min = 0;
sec = 0;
end
else
hr = 0;
min = 0;
sec = 0;
end
date_vec = [y, mm, arrive_d, hr, min, sec];
if strcmp(print_out,'yes')
date_arrive = datestr(date_vec,'dd/mm/yyyy at HH:MM:SS UT');
da = sprintf('The spacecraft will arrive on %s', date_arrive);
fprintf(da)
disp(' ')
end
end