/[projects]/dao/DelphiScanner/Components/tpsystools_4.04/examples/CBuilder/AstCalU.cpp
ViewVC logotype

Annotation of /dao/DelphiScanner/Components/tpsystools_4.04/examples/CBuilder/AstCalU.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2671 - (hide annotations) (download)
Tue Aug 25 18:15:15 2015 UTC (8 years, 9 months ago) by torben
File size: 10750 byte(s)
Added tpsystools component
1 torben 2671 // ***** BEGIN LICENSE BLOCK *****
2     // * Version: MPL 1.1
3     // *
4     // * The contents of this file are subject to the Mozilla Public License Version
5     // * 1.1 (the "License"); you may not use this file except in compliance with
6     // * the License. You may obtain a copy of the License at
7     // * http://www.mozilla.org/MPL/
8     // *
9     // * Software distributed under the License is distributed on an "AS IS" basis,
10     // * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11     // * for the specific language governing rights and limitations under the
12     // * License.
13     // *
14     // * The Original Code is TurboPower SysTools
15     // *
16     // * The Initial Developer of the Original Code is
17     // * TurboPower Software
18     // *
19     // * Portions created by the Initial Developer are Copyright (C) 1996-2002
20     // * the Initial Developer. All Rights Reserved.
21     // *
22     // * Contributor(s):
23     // *
24     // * ***** END LICENSE BLOCK *****
25     //---------------------------------------------------------------------------
26     #include <vcl\vcl.h>
27     #pragma hdrstop
28     #include "AstCalU.h"
29     //---------------------------------------------------------------------------
30     #pragma package(smart_init)
31     #pragma link "StDate"
32     #pragma link "StAstro"
33     #pragma link "StAstroP"
34    
35     #pragma resource "*.dfm"
36     TForm1 *Form1;
37     //---------------------------------------------------------------------------
38     __fastcall TForm1::TForm1(TComponent* Owner)
39     : TForm(Owner)
40     {
41     }
42     //---------------------------------------------------------------------------
43     void __fastcall TForm1::FormCreate(TObject *Sender)
44     {
45     TheDT.D = CurrentDate();
46     TheDT.T = CurrentTime();
47    
48     StDateToDMY(TheDT.D, D, M, Y);
49     MonthEF->Text = IntToStr(M);
50     DateEF->Text = IntToStr(D);
51     YearEF->Text = IntToStr(Y);
52    
53     LongEF->Text = FloatToStr(-105.27);
54     LatEF->Text = FloatToStr(38.87);
55    
56     DoCalcTimes();
57     Button1Click(this);
58     }
59     //---------------------------------------------------------------------------
60     void __fastcall TForm1::Timer1Timer(TObject *Sender)
61     {
62     DoCalcTimes();
63     }
64     //---------------------------------------------------------------------------
65     void __fastcall TForm1::DoCalcTimes()
66     {
67     TStTime TT;
68    
69     LocalTimeEF->Text = CurrentTimeString("hh:mm:ss", false);
70     TheDT.T = CurrentTime();
71     TT = floor(SiderealTime(TheDT) * 240 + 0.5);
72     SiderealTimeEF->Text = StTimeToTimeString("hh:mm:ss", TT, false);
73     }
74     //---------------------------------------------------------------------------
75     void __fastcall TForm1::DoFixedCalcs() {
76     int Y, M, D;
77     TStDateTimeRec DTR;
78     TStMoonPosRec MPR;
79     TStPosRec SPR;
80     String TS;
81     TStLunarRecord LR;
82     TStPlanetsArray PA;
83    
84     //Calculate Positions
85    
86     SPR = SunPos(TheDT);
87     PositionsLB->Items->Add("Sun " + HoursMin(SPR.RA) + " " + DegsMin(SPR.DC));
88    
89     MPR = MoonPos(TheDT);
90     PositionsLB->Items->Add("Moon " + HoursMin(MPR.RA) + " " + DegsMin(MPR.DC));
91     PlanetsPos(AstJulianDate(TheDT.D) + TheDT.T/86400, PA);
92     PositionsLB->Items->Add("Mercury " + HoursMin(PA[1].RA) + " " + DegsMin(PA[1].DC));
93     PositionsLB->Items->Add("Venus " + HoursMin(PA[2].RA) + " " + DegsMin(PA[2].DC));
94     PositionsLB->Items->Add("Mars " + HoursMin(PA[3].RA) + " " + DegsMin(PA[3].DC));
95     PositionsLB->Items->Add("Jupiter " + HoursMin(PA[4].RA) + " " + DegsMin(PA[4].DC));
96     PositionsLB->Items->Add("Saturn " + HoursMin(PA[5].RA) + " " + DegsMin(PA[5].DC));
97     PositionsLB->Items->Add("Uranus " + HoursMin(PA[6].RA) + " " + DegsMin(PA[6].DC));
98     PositionsLB->Items->Add("Neptune " + HoursMin(PA[7].RA) + " " + DegsMin(PA[7].DC));
99     PositionsLB->Items->Add("Pluto " + HoursMin(PA[8].RA) + " " + DegsMin(PA[8].DC));
100    
101     //Calculate lunar phases
102    
103     if (LunarPhase(TheDT) >= 0)
104     PhaseLabel->Caption = "Waxing";
105     else
106     PhaseLabel->Caption = "Waning";
107    
108     LR = NewMoon(TheDT.D);
109     NMFirstDate->Text = StDateToDateString("mm/dd", LR.T[0].D, false);
110     NMFirstTime->Text = StTimeToTimeString("hh:mm", LR.T[0].T, false);
111     if (LR.T[1].D != BadDate) {
112     NMSecondDate->Text = StDateToDateString("mm/dd", LR.T[1].D, false);
113     NMSecondTime->Text = StTimeToTimeString("hh:mm", LR.T[1].T, false);
114     }
115     else {
116     NMSecondDate->Text = "";
117     NMSecondTime->Text = "";
118     };
119    
120     LR = FirstQuarter(TheDT.D);
121     FQFirstDate->Text = StDateToDateString("mm/dd", LR.T[0].D, false);
122     FQFirstTime->Text = StTimeToTimeString("hh:mm", LR.T[0].T, false);
123     if (LR.T[1].D != BadDate) {
124     FQSecondDate->Text = StDateToDateString("mm/dd", LR.T[1].D, false);
125     FQSecondTime->Text = StTimeToTimeString("hh:mm", LR.T[1].T, false);
126     }
127     else {
128     FQSecondDate->Text = "";
129     FQSecondTime->Text = "";
130     };
131    
132     LR = FullMoon(TheDT.D);
133     FMFirstDate->Text = StDateToDateString("mm/dd", LR.T[0].D, false);
134     FMFirstTime->Text = StTimeToTimeString("hh:mm", LR.T[0].T, false);
135     if (LR.T[1].D != BadDate) {
136     FMSecondDate->Text = StDateToDateString("mm/dd", LR.T[1].D, false);
137     FMSecondTime->Text = StTimeToTimeString("hh:mm", LR.T[1].T, false);
138     }
139     else {
140     FMSecondDate->Text = "";
141     FMSecondTime->Text = "";
142     };
143    
144     LR = LastQuarter(TheDT.D);
145     LQFirstDate->Text = StDateToDateString("mm/dd", LR.T[0].D, false);
146     LQFirstTime->Text = StTimeToTimeString("hh:mm", LR.T[0].T, false);
147     if (LR.T[1].D != BadDate) {
148     LQSecondDate->Text = StDateToDateString("mm/dd", LR.T[1].D, false);
149     LQSecondTime->Text = StTimeToTimeString("hh:mm", LR.T[1].T, false);
150     }
151     else {
152     LQSecondDate->Text = "";
153     LQSecondTime->Text = "";
154     };
155    
156    
157     //Calculate Next/Previous
158    
159     DTR = PrevNewMoon(TheDT.D);
160     if (DTR.D != BadDate) {
161     NMPrevDate->Text = StDateToDateString("mm/dd", DTR.D, false);
162     NMPrevTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
163     }
164     else {
165     NMPrevDate->Text = "";
166     NMPrevTime->Text = "";
167     };
168    
169     DTR = NextNewMoon(TheDT.D);
170     if (DTR.D != BadDate) {
171     NMNextDate->Text = StDateToDateString("mm/dd", DTR.D, false);
172     NMNextTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
173     }
174     else {
175     NMNextDate->Text = "";
176     NMNextTime->Text = "";
177     };
178    
179     DTR = PrevFirstQuarter(TheDT.D);
180     if (DTR.D != BadDate) {
181     FQPrevDate->Text = StDateToDateString("mm/dd", DTR.D, false);
182     FQPrevTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
183     }
184     else {
185     FQPrevDate->Text = "";
186     FQPrevTime->Text = "";
187     };
188    
189     DTR = NextFirstQuarter(TheDT.D);
190     if (DTR.D != BadDate) {
191     FQNextDate->Text = StDateToDateString("mm/dd", DTR.D, false);
192     FQNextTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
193     }
194     else {
195     FQNextDate->Text = "";
196     FQNextTime->Text = "";
197     };
198    
199    
200     DTR = PrevFullMoon(TheDT.D);
201     if (DTR.D != BadDate) {
202     FMPrevDate->Text = StDateToDateString("mm/dd", DTR.D, false);
203     FMPrevTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
204     }
205     else {
206     FMPrevDate->Text = "";
207     FMPrevTime->Text = "";
208     };
209    
210     DTR = NextFullMoon(TheDT.D);
211     if (DTR.D != BadDate) {
212     FMNextDate->Text = StDateToDateString("mm/dd", DTR.D, false);
213     FMNextTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
214     }
215     else {
216     FMNextDate->Text = "";
217     FMNextTime->Text = "";
218     };
219    
220    
221     DTR = PrevLastQuarter(TheDT.D);
222     if (DTR.D != BadDate) {
223     LQPrevDate->Text = StDateToDateString("mm/dd", DTR.D, false);
224     LQPrevTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
225     }
226     else {
227     LQPrevDate->Text = "";
228     LQPrevTime->Text = "";
229     };
230    
231     DTR = NextLastQuarter(TheDT.D);
232     if (DTR.D != BadDate) {
233     LQNextDate->Text = StDateToDateString("mm/dd", DTR.D, false);
234     LQNextTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
235     }
236     else {
237     LQNextDate->Text = "";
238     LQNextTime->Text = "";
239     };
240    
241     //Calculate Other Events
242    
243     StDateToDMY(TheDT.D, D, M, Y);
244     EasterEF->Text = StDateToDateString("mm/dd", Easter(Y, 0), false);
245    
246    
247     DTR = Equinox(Y, 0, True);
248     SpringDate->Text = StDateToDateString("mm/dd", DTR.D, false);
249     SpringTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
250    
251    
252     DTR = Equinox(Y, 0, false);
253     FallDate->Text = StDateToDateString("mm/dd", DTR.D, false);
254     FallTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
255    
256    
257     DTR = Solstice(Y, 0, True);
258     SummerDate->Text = StDateToDateString("mm/dd", DTR.D, false);
259     SummerTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
260    
261    
262     DTR = Solstice(Y, 0, false);
263     WinterDate->Text = StDateToDateString("mm/dd", DTR.D, false);
264     WinterTime->Text = StTimeToTimeString("hh:mm", DTR.T, false);
265     };
266     //---------------------------------------------------------------------------
267     void __fastcall TForm1::DoCalcs(double ObsLong, double ObsLat) {
268     SunlightEF->Text = StTimeToTimeString("hh:mm",
269     AmountOfSunlight(TheDT.D, ObsLong, ObsLat), false);
270    
271     RS = SunRiseSet(TheDT.D, ObsLong, ObsLat);
272     SunRiseEF->Text = StTimeToTimeString("hh:mm", RS.ORise, false);
273     SunSetEF->Text = StTimeToTimeString("hh:mm", RS.OSet, false);
274    
275     RS = MoonRiseSet(TheDT.D, ObsLong, ObsLat);
276     MoonRiseEF->Text = StTimeToTimeString("hh:mm", RS.ORise, false);
277     MoonSetEF->Text = StTimeToTimeString("hh:mm", RS.OSet, false);
278    
279     RS = Twilight(TheDT.D, ObsLong, ObsLat, ttAstronomical);
280     TwiStartEF->Text = StTimeToTimeString("hh:mm", RS.ORise, false);
281     TwiEndEF->Text = StTimeToTimeString("hh:mm", RS.OSet, false);
282     };
283     //---------------------------------------------------------------------------
284     void __fastcall TForm1::Button1Click(TObject *Sender)
285     {
286     try {
287     M = StrToInt(MonthEF->Text);
288     if ((M < 1) || (M > 12)) {
289     ShowMessage("Month value out of range (1..12)");
290     return;
291     };
292    
293     D = StrToInt(DateEF->Text);
294     if ((D < 1) || (D > 31)) {
295     ShowMessage("Date value out of range (1..31)");
296     return;
297     };
298    
299     Y = StrToInt(YearEF->Text);
300     if ((Y < 1800) || (Y > 2200)) {
301     ShowMessage("Year value out of range (1800..2200)");
302     return;
303     };
304    
305     TheDT.D = DMYtoStDate(D, M, Y, 0);
306     if (TheDT.D == BadDate) {
307     ShowMessage("Invalid date");
308     return;
309     };
310     TheDT.T = CurrentTime();
311    
312     ObsLong = StrToFloat(LongEF->Text);
313     if ((ObsLong < -180) || (ObsLong > 180)) {
314     ShowMessage("Longitude out of range (-180..180)");
315     return;
316     };
317    
318     ObsLat = StrToFloat(LatEF->Text);
319     if ((ObsLat < -90) || (ObsLat > 90)) {
320     ShowMessage("Latitude out of range (-90..90)");
321     return;
322     };
323    
324     PositionsLB->Clear();
325     DoFixedCalcs();
326     DoCalcs(ObsLong, ObsLat);
327     }
328     catch(...) {
329     ShowMessage("One or more entry fields has illegal data");
330     };
331     };
332     //---------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20