-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathlunar_eclipse.cs
68 lines (56 loc) · 2.24 KB
/
lunar_eclipse.cs
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
using System;
using System.Linq;
using demo_helper;
using CosineKitty;
namespace lunar_eclipse
{
class Program
{
static int Main(string[] args)
{
AstroTime time;
switch (args.Length)
{
case 0:
time = new AstroTime(DateTime.Now);
break;
case 1:
time = DemoHelper.ParseTime("lunar_eclipse", args[0]);
break;
default:
Console.WriteLine("USAGE: lunar_eclipse [date]");
return 1;
}
var eclipseList = Astronomy.LunarEclipsesAfter(time)
.Where(eclipse => eclipse.kind != EclipseKind.Penumbral)
.Take(10);
foreach (LunarEclipseInfo eclipse in eclipseList)
PrintEclipse(eclipse);
return 0;
}
static void PrintEclipse(LunarEclipseInfo eclipse)
{
// Calculate beginning/ending of different phases
// of an eclipse by subtracting/adding the peak time
// with the number of minutes indicated by the "semi-duration"
// fields sd_partial and sd_total.
const double MINUTES_PER_DAY = 24 * 60;
AstroTime p1 = eclipse.peak.AddDays(-eclipse.sd_partial / MINUTES_PER_DAY);
Console.WriteLine("{0} Partial eclipse begins.", p1);
if (eclipse.sd_total > 0.0)
{
AstroTime t1 = eclipse.peak.AddDays(-eclipse.sd_total / MINUTES_PER_DAY);
Console.WriteLine("{0} Total eclipse begins.", t1);
}
Console.WriteLine("{0} Peak of {1} eclipse.", eclipse.peak, eclipse.kind.ToString().ToLowerInvariant());
if (eclipse.sd_total > 0.0)
{
AstroTime t2 = eclipse.peak.AddDays(+eclipse.sd_total / MINUTES_PER_DAY);
Console.WriteLine("{0} Total eclipse ends.", t2);
}
AstroTime p2 = eclipse.peak.AddDays(+eclipse.sd_partial / MINUTES_PER_DAY);
Console.WriteLine("{0} Partial eclipse ends.", p2);
Console.WriteLine();
}
}
}