├── .gitattributes
├── .gitignore
├── stcalc.sln
└── stcalc
├── Moment.cs
├── Program.cs
├── Properties
└── launchSettings.json
├── RightAscension.cs
└── stcalc.csproj
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------
/stcalc.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29728.190
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stcalc", "stcalc\stcalc.csproj", "{C8245676-D235-4726-A620-87F559B1CBAC}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {C8245676-D235-4726-A620-87F559B1CBAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {C8245676-D235-4726-A620-87F559B1CBAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {C8245676-D235-4726-A620-87F559B1CBAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {C8245676-D235-4726-A620-87F559B1CBAC}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {E301307C-D8E3-46EE-922A-6B14A7619B16}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/stcalc/Moment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace stcalc
4 | {
5 | ///
6 | /// A moment is a specific point in time down to the optional millisecond.
7 | ///
8 | public struct Moment
9 | {
10 | public int Year { get; }
11 | public int Month { get; }
12 | public int Day { get; }
13 | public int Hour { get; }
14 | public int Minute { get; }
15 | public int Second { get; }
16 | public int Millisecond { get; }
17 |
18 | public Moment(DateTime dt)
19 | {
20 | Year = dt.Year;
21 | Month = dt.Month;
22 | Day = dt.Day;
23 | Hour = dt.Hour;
24 | Minute = dt.Minute;
25 | Second = dt.Second;
26 | Millisecond = dt.Millisecond;
27 | }
28 |
29 | ///
30 | /// Creates a Moment with known values down to the millisecond.
31 | ///
32 | ///
33 | ///
34 | ///
35 | ///
36 | ///
37 | ///
38 | ///
39 | public Moment(int year, int month, int day, int hour, int minute, int second = 0, int millisecond = 0)
40 | {
41 | Year = year;
42 | Month = month;
43 | Day = day;
44 | Hour = hour;
45 | Minute = minute;
46 | Second = second;
47 | Millisecond = millisecond;
48 | }
49 |
50 | ///
51 | /// Creates a Moment with known values using a fraction to represent the day
52 | /// of the month as well as the hour, minute, second, and millisecond component.
53 | /// For example, 4.812 is the 4th day at 19:29 (7:29 PM).
54 | ///
55 | ///
56 | ///
57 | ///
58 | public Moment(int year, int month, double day)
59 | {
60 | if (double.IsNaN(day))
61 | {
62 | throw new ArgumentException("day must be a valid value.");
63 | }
64 |
65 | Year = year;
66 | Month = month;
67 |
68 | // leverage the C# TimeSpan struct
69 | var ts = TimeSpan.FromDays(day);
70 | Day = ts.Days;
71 | Hour = ts.Hours;
72 | Minute = ts.Minutes;
73 | Second = ts.Seconds;
74 | Millisecond = ts.Milliseconds;
75 | }
76 |
77 | ///
78 | /// Creates a Moment with a known Julian Day (JD) value.
79 | ///
80 | ///
81 | public Moment(double julianDay)
82 | {
83 | if (double.IsNaN(julianDay))
84 | {
85 | throw new ArgumentException("julianDay must be a valid value.");
86 | }
87 |
88 | double A;
89 | double B;
90 | int C;
91 | double D;
92 | int E;
93 | double jd = julianDay + 0.5;
94 | double Z = Math.Truncate(jd);
95 | double F = jd - Math.Truncate(jd);
96 |
97 | if (Z < 2299161)
98 | {
99 | A = Z;
100 | }
101 | else
102 | {
103 | var a = (int)((Z - 1867216.25) / 36524.25);
104 | A = Z + 1 + a - (int)(a / 4);
105 | }
106 |
107 | B = A + 1524;
108 | C = (int)((B - 122.1) / 365.25);
109 | D = (int)(365.25 * C);
110 | E = (int)((B - D) / 30.6001);
111 |
112 | int Y;
113 | int M;
114 | double day = B - D - (int)(30.6001 * E) + F;
115 | switch (E)
116 | {
117 | case 14:
118 | case 15:
119 | M = E - 13;
120 | break;
121 |
122 | default:
123 | M = E - 1;
124 | break;
125 | }
126 |
127 | switch (M)
128 | {
129 | case 1:
130 | case 2:
131 | Y = C - 4715;
132 | break;
133 |
134 | default:
135 | Y = C - 4715;
136 | break;
137 | }
138 |
139 | Year = Y;
140 | Month = M;
141 |
142 | // leverage the C# TimeSpan struct
143 | var ts = TimeSpan.FromDays(day);
144 | Day = ts.Days;
145 | Hour = ts.Hours;
146 | Minute = ts.Minutes;
147 | Second = ts.Seconds;
148 | Millisecond = ts.Milliseconds;
149 | }
150 |
151 | public double DayOfMonth
152 | {
153 | get
154 | {
155 | return Day + (Hour / 24.0) + (Minute / 1440.0) + (Second + Millisecond / 1000.0) / 86400.0;
156 | }
157 | }
158 |
159 | ///
160 | /// A Julian Day (JD) is a continuous count of days and fractions thereof
161 | /// starting at 1 Jan -4712 at noon UTC to a given point in time thereafter.
162 | ///
163 | public double JulianDay
164 | {
165 | get
166 | {
167 | int Y = Year;
168 | int M = Month;
169 | double B = 0; // Julian calendar default
170 |
171 | // if the date is Jan or Feb then it is considered to be in the
172 | // 13th or 14th month of the preceding year.
173 | switch (M)
174 | {
175 | case 1:
176 | case 2:
177 | Y -= 1;
178 | M += 12;
179 | break;
180 |
181 | default:
182 | break;
183 | }
184 |
185 | if (!IsJulianDate()) // convert to Gregorian calendar
186 | {
187 | double A = Math.Floor(Y / 100.0);
188 | B = 2 - A + Math.Floor(A / 4);
189 | }
190 |
191 | return Math.Floor(365.25 * (Y + 4716)) + Math.Floor(30.6001 * (M + 1)) + DayOfMonth + B - 1524.5;
192 | }
193 | }
194 |
195 | public double JD
196 | {
197 | get
198 | {
199 | return JulianDay;
200 | }
201 | }
202 |
203 | public double JDE
204 | {
205 | get
206 | {
207 | return JulianDay;
208 | }
209 | }
210 |
211 | ///
212 | /// Time T is measured in Julian centuries of 36525 ephemeris days from the epoch J2000.0
213 | ///
214 | public double TimeT
215 | {
216 | get
217 | {
218 | return (JulianDay - 2451545.0) / 36525;
219 | }
220 | }
221 |
222 | ///
223 | /// Day D is the number of days (and decimals thereof) from the epoch J2000.0
224 | ///
225 | public double DayD
226 | {
227 | get
228 | {
229 | return JulianDay - 2451545.0;
230 | }
231 | }
232 |
233 | ///
234 | /// Pope Gregory introduced the Gregorian calendar in October 1582 when the
235 | /// calendar had drifted 10 days. Dates prior to 4 Oct 1582 are Julian dates
236 | /// and dates after 15 Oct 1582 are Gregorian dates. Any date in the gap is
237 | /// invalid on the Gregorian calendar.
238 | ///
239 | ///
240 | public bool IsJulianDate()
241 | {
242 | if (Year > 1582)
243 | return false;
244 |
245 | if (Year < 1582)
246 | return true;
247 |
248 | // year is 1582 so check month
249 | if (Month > 10)
250 | return false;
251 |
252 | if (Month < 10)
253 | return true;
254 |
255 | // month is 10 so check days
256 | if (Day > 14)
257 | return false;
258 |
259 | return true;
260 | }
261 |
262 | public bool IsGregorianDate()
263 | {
264 | if (Year > 1582)
265 | return true;
266 |
267 | if (Year < 1582)
268 | return false;
269 |
270 | // year is 1582 so check month
271 | if (Month > 10)
272 | return true;
273 |
274 | if (Month < 10)
275 | return false;
276 |
277 | // month is 10 so check days
278 | if (Day > 5)
279 | return true;
280 |
281 | return false;
282 | }
283 |
284 | public override bool Equals(object obj)
285 | {
286 | if (!(obj is Moment))
287 | return false;
288 |
289 | Moment moment = (Moment)obj;
290 | return moment.JulianDay == this.JulianDay;
291 | }
292 |
293 | public override string ToString()
294 | {
295 | DateTime dt = new DateTime(Year, Month, Day, Hour, Minute, Second, DateTimeKind.Utc);
296 | return dt.ToString("u");
297 | }
298 |
299 | public static bool operator ==(Moment m1, Moment m2)
300 | {
301 | return m1.JulianDay == m2.JulianDay;
302 | }
303 |
304 | public static bool operator !=(Moment m1, Moment m2)
305 | {
306 | return m1.JulianDay != m2.JulianDay;
307 | }
308 |
309 | public override int GetHashCode()
310 | {
311 | return base.GetHashCode();
312 | }
313 | }
314 | }
315 |
--------------------------------------------------------------------------------
/stcalc/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 |
4 | namespace stcalc
5 | {
6 | public class Program
7 | {
8 | private const string _usage = "Enter your longitude and (optionally) local date and time. Usage: stcalc -122.675 2020-03-03 13:00";
9 | static void Main(string[] args)
10 | {
11 | // Test if input arguments were supplied.
12 | if (args.Length < 1)
13 | {
14 | Console.WriteLine("Please enter your longitude. If you leave date and time blank the current moment is used.");
15 | Console.WriteLine(_usage);
16 | return;
17 | }
18 |
19 | if (!IsValidLongitude(args[0], out double longitude))
20 | {
21 | Console.WriteLine("Please enter a valid longitude between -180 and 180.");
22 | Console.WriteLine(_usage);
23 | return;
24 | }
25 |
26 | var dateValue = (args.Length > 1) ? args[1] : string.Empty;
27 | if (!IsValidDate(dateValue, out DateTime d))
28 | {
29 | Console.WriteLine("Please enter a valid date in the format YYYY-MM-DD");
30 | Console.WriteLine(_usage);
31 | return;
32 | }
33 |
34 | var timeValue = (args.Length > 2) ? args[2] : string.Empty;
35 | if (!IsValidTime(timeValue, out TimeSpan ts))
36 | {
37 | Console.WriteLine("Please enter a valid time in the format HH:MM");
38 | Console.WriteLine(_usage);
39 | return;
40 | }
41 |
42 | DateTime localDateTime = d + ts;
43 | DateTime utcDateTime = TimeZoneInfo.ConvertTimeToUtc(localDateTime, TimeZoneInfo.Local);
44 |
45 | // lines 55 thru 59 are from Meeus, Chap 12 (pp 87-89)
46 | var moment = new Moment(utcDateTime);
47 | var JD = moment.JulianDay;
48 | var T = ((JD - 2451545.0) / 36525);
49 | var theta0 = 280.46061837 + 360.98564736629 * (JD - 2451545.0) + (0.000387933 * T * T) - (T * T * T / 38710000.0); // (12.4)
50 | var gmstRA = new RightAscension(ReduceAngle(theta0));
51 |
52 | /*
53 | From Textbook on Spherical Astronomy, 6th Ed. by W.M. Smart (p. 41):
54 |
55 | Sidereal time at Greenwich = GST + longitude l of your location east or west of Greenwich.
56 | In Portland, Oregon (-122.67) this results in a subtraction from GST. The result is then
57 | converted into hours, minutes, and seconds via 15 deg = 1h, 15' = 1m, and 15'' = 1s. This
58 | is the local sidereal time (LST).
59 | */
60 |
61 | var lmstRA = new RightAscension(gmstRA.ToDecimalDegrees() + longitude);
62 |
63 | Console.WriteLine("Longitude: " + longitude);
64 | Console.WriteLine("Local DateTime: " + localDateTime.ToString());
65 | Console.WriteLine("UTC DateTime: " + utcDateTime.ToString());
66 | Console.WriteLine(Environment.NewLine);
67 |
68 | Console.WriteLine("JD: " + JD);
69 | Console.WriteLine("T: " + T);
70 | Console.WriteLine("theta0 from Meeus formula (12.4): " + theta0);
71 | Console.WriteLine(Environment.NewLine);
72 |
73 | Console.WriteLine("Greenwich Mean Sidereal Time (dec deg): " + ReduceAngle(theta0));
74 | Console.WriteLine("Greenwich Mean Sidereal Time (HMS): " + gmstRA.ToString());
75 | Console.WriteLine("Local Mean Sidereal Time (dec deg): " + lmstRA.ToDecimalDegrees());
76 | Console.WriteLine("Local Mean Sidereal Time (HMS): " + lmstRA.ToString());
77 | Console.WriteLine(Environment.NewLine);
78 |
79 | Console.WriteLine("Press ENTER to exit.");
80 | Console.ReadLine();
81 | }
82 |
83 | private static bool IsValidLongitude(string value, out double d)
84 | {
85 | bool test = double.TryParse(value, out d);
86 | if (!test)
87 | {
88 | return false;
89 | }
90 |
91 | return (d >= -180 && d <= 180);
92 | }
93 |
94 | private static bool IsValidDate(string value, out DateTime d)
95 | {
96 | if (string.IsNullOrEmpty(value))
97 | {
98 | d = DateTime.Today;
99 | return false;
100 | }
101 |
102 | string pattern = "yyyy-MM-dd";
103 | CultureInfo ci = CultureInfo.InvariantCulture;
104 | DateTimeStyles dts = DateTimeStyles.None;
105 | try
106 | {
107 | return DateTime.TryParseExact(value, pattern, ci, dts, out d);
108 | }
109 | catch
110 | {
111 | Console.WriteLine("Invalid date or not in format YYYY-MM-DD.");
112 | d = DateTime.Today;
113 | return false;
114 | }
115 | }
116 |
117 | private static bool IsValidTime(string value, out TimeSpan ts)
118 | {
119 | if (string.IsNullOrEmpty(value))
120 | {
121 | ts = DateTime.Now.TimeOfDay;
122 | return false;
123 | }
124 |
125 | try
126 | {
127 | return TimeSpan.TryParse(value, out ts);
128 | }
129 | catch
130 | {
131 | Console.WriteLine("Invalid time or not in format HH:MM.");
132 | ts = DateTime.Now.TimeOfDay;
133 | return false;
134 | }
135 | }
136 |
137 | ///
138 | /// For very large angles reduce to put in interval between 0 and 360
139 | ///
140 | ///
141 | ///
142 | private static double ReduceAngle(double d)
143 | {
144 | d %= 360;
145 | if (d < 0)
146 | {
147 | d += 360;
148 | }
149 |
150 | return d;
151 | }
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/stcalc/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "stcalc": {
4 | "commandName": "Project",
5 | "commandLineArgs": "-122.67563 2020-03-19 20:50"
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/stcalc/RightAscension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace stcalc
4 | {
5 | public struct RightAscension
6 | {
7 | public RightAscension(double hours, double minutes, double seconds)
8 | {
9 | if (hours < 0 || hours > 23)
10 | {
11 | throw new ArgumentException("Hours must be between 0 and 23", "hours");
12 | }
13 |
14 | if (minutes < 0 || minutes > 59)
15 | {
16 | throw new ArgumentException("Minutes must be between 0 and 59", "minutes");
17 | }
18 |
19 | if (seconds < 0 || seconds > 59)
20 | {
21 | throw new ArgumentException("Seconds must be between 0 and 59", "seconds");
22 | }
23 |
24 | Hours = hours;
25 | Minutes = minutes;
26 | Seconds = seconds;
27 | }
28 |
29 | public RightAscension(double decimalDegrees)
30 | {
31 | Hours = ToHours(decimalDegrees);
32 | Minutes = ToMinutes(decimalDegrees);
33 | Seconds = ToSeconds(decimalDegrees);
34 | }
35 |
36 | public double Hours { get; }
37 | public double Minutes { get; }
38 | public double Seconds { get; }
39 |
40 | public double ToDecimalDegrees() => (Hours + (Minutes / 60) + (Seconds / 3600)) * 15;
41 | public override string ToString()
42 | {
43 | var d = ToDecimalDegrees();
44 | var h = (int)d / 15;
45 | var m = (int)(((d / 15) - h) * 60);
46 | var s = ((((d / 15) - h) * 60) - m) * 60;
47 | var ss = Math.Round(s);
48 | return $"{h}h {m}m {ss}s";
49 | }
50 |
51 | private static double ToHours(double d)
52 | {
53 | return d / 15;
54 | }
55 |
56 | private static double ToMinutes(double d)
57 | {
58 | var h = ToHours(d);
59 | return ((d / 15) - h) * 60;
60 | }
61 |
62 | private static double ToSeconds(double d)
63 | {
64 | var h = ToHours(d);
65 | var m = ToMinutes(d);
66 | return ((((d / 15) - h) * 60) - m) * 60;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/stcalc/stcalc.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------