3 * wmSun-1.03 (C) 1999 Mike Henderson (mghenderson@lanl.gov)
5 * - Shows Sun Rise/Set Times....
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA
28 * - support for 8-bit displays.
29 * - more detailed documentation.
31 * - add buttons to play will date and lat lon...
32 * Could be something like this;
33 * First click brings up buttons to change date.
34 * Second click brings up buttons to change lat/lon.
35 * Third goes back to display
36 * Set time delay to go back to display if user doesnt do it...
44 * Version 1.03 - released February 4, 1999.
45 * cosmetic for AfterStep users. removed spurious black line at RHS edge an mask.
48 * Version 1.02 - released January 12, 1999.
49 * Added support for User-specified date and Time difference so that
50 * you can have the display be correct in local time even for remote
51 * lat/lons. (I am in Hawaii right now. I dont want to reset the time on
52 * my laptop, so with these new options I can still get the correct
53 * local times of rise/set. Sunset is awesome here in Kona!!! And the calcs
54 * seem to be quite good -- it's a good test here because the Sun sets over
55 * the Pacific (no mountains are in the way)).
57 * Version 1.01 - released January 6, 1999.
58 * Fixed stupid bug in Date change montior.
60 * Version 1.0 - released January 5, 1999.
80 #include "wmgeneral/wmgeneral.h"
81 #include "wmSun_master.xpm"
82 #include "wmSun_mask.xbm"
87 * Delay between refreshes (in microseconds)
90 #define WMSUN_VERSION "1.03"
92 #define DegPerRad 57.29577951308232087680
93 #define RadPerDeg 0.01745329251994329576
99 void ParseCMDLine(int argc
, char *argv
[]);
100 void pressEvent(XButtonEvent
*xev
);
101 SunRise(int year
, int month
, int day
, double LocalHour
, double *UTRise
,
104 int ToggleWindow
= 0;
107 int UseUserTimeDiff
= 0;
110 double Glat
, Glon
, SinGlat
, CosGlat
, TimeZone
, UserTimeDiff
;
113 int xDigit
[11] = {8, 18, 27, 37, 46, 55, 64, 74, 83, 92, 102};
121 int main(int argc
, char *argv
[]) {
127 struct tm
*GMTTime
, *LocalTime
;
130 int Year
, Month
, OldLocalDayOfMonth
;
131 int LocalDayOfMonth
, DayOfMonth
;
132 long CurrentLocalTime
, CurrentGMTTime
, date
;
133 double UT
, val
, LTRise
, LTSet
, LocalHour
, hour24();
142 * Parse any command line arguments.
145 ParseCMDLine(argc
, argv
);
146 Glat
*= RadPerDeg
; SinGlat
= sin( Glat
); CosGlat
= cos( Glat
);
150 openXwindow(argc
, argv
, wmSun_master
, wmSun_mask_bits
, wmSun_mask_width
, wmSun_mask_height
);
160 OldLocalDayOfMonth
= -999;
173 * The Moon Ephemeris calculations are somewhat costly (the Moon is one of the most
174 * difficult objects to compute position for). So only process every nMAXth cycle of this
175 * loop. We run outer loop it faster to catch expose events, button presses, etc...
184 CurrentGMTTime
= time(CurrentTime
); GMTTime
= gmtime(&CurrentGMTTime
);
185 DayOfMonth
= GMTTime
->tm_mday
;
187 UT
= GMTTime
->tm_hour
+ GMTTime
->tm_min
/60.0 + GMTTime
->tm_sec
/3600.0;
188 Year
= GMTTime
->tm_year
+1900;
189 Month
= GMTTime
->tm_mon
+1;
192 CurrentLocalTime
= CurrentGMTTime
; LocalTime
= localtime(&CurrentLocalTime
);
193 LocalDayOfMonth
= LocalTime
->tm_mday
;
195 if ((OldLocalDayOfMonth
!= LocalDayOfMonth
)||(Flag
)){
208 date
= Year
*10000 + Month
*100 + DayOfMonth
;
210 LocalHour
= LocalTime
->tm_hour
+ LocalTime
->tm_min
/60.0 + LocalTime
->tm_sec
/3600.0;
211 TimeZone
= (UseUserTimeDiff
) ? UserTimeDiff
: UT
- LocalHour
;
214 * Clear Plotting area
216 copyXPMArea(65, 5, 54, 54, 5, 5);
221 * Compute Sun Rise/Set Times in Local Time
223 SunRise(Year
, Month
, DayOfMonth
, LocalHour
, <Rise
, <Set
);
227 H
= (int)val
; val
= (val
-H
)*60.0;
229 copyXPMArea(xDigit
[H
/10], 73, 7, 9, 17, 13);
230 copyXPMArea(xDigit
[H
%10], 73, 7, 9, 17+7, 13);
231 copyXPMArea(xDigit
[10], 75, 3, 6, 17+15, 15);
232 copyXPMArea(xDigit
[M
/10], 73, 7, 9, 17+19, 13);
233 copyXPMArea(xDigit
[M
%10], 73, 7, 9, 17+26, 13);
235 copyXPMArea(10, 84, 28, 7, 19, 15);
241 H
= (int)val
; val
= (val
-H
)*60.0;
243 copyXPMArea(xDigit
[H
/10], 73, 7, 9, 17, 40);
244 copyXPMArea(xDigit
[H
%10], 73, 7, 9, 17+7, 40);
245 copyXPMArea(xDigit
[10], 75, 3, 6, 17+15, 42);
246 copyXPMArea(xDigit
[M
/10], 73, 7, 9, 17+19, 40);
247 copyXPMArea(xDigit
[M
%10], 73, 7, 9, 17+26, 40);
249 copyXPMArea(10, 84, 28, 7, 19, 40);
254 OldLocalDayOfMonth
= LocalDayOfMonth
;
260 * Update the counter.
274 * Process any pending X events.
276 while(XPending(display
)){
277 XNextEvent(display
, &event
);
283 pressEvent(&event
.xbutton
);
296 * Redraw and wait for next update
318 void ParseCMDLine(int argc
, char *argv
[]) {
322 for (i
= 1; i
< argc
; i
++) {
324 if (!strcmp(argv
[i
], "-display")){
328 } else if (!strcmp(argv
[i
], "-lat")){
330 Glat
= atof(argv
[++i
]);
332 } else if (!strcmp(argv
[i
], "-lon")){
334 Glon
= atof(argv
[++i
]);
336 } else if (!strcmp(argv
[i
], "-td")){
339 UserTimeDiff
= atof(argv
[++i
]);
341 } else if (!strcmp(argv
[i
], "-date")){
344 UserDate
= atoi(argv
[++i
]);
347 printf("\nwmSun version: %s\n", WMSUN_VERSION
);
348 printf("\nusage: wmSun [-display <Display>] [-lat <Latitude>] [-lon <Longitude>] [-h]\n\n");
349 printf("\t-display <Display>\tUse alternate X display.\n");
350 printf("\t-lat <Latitude>\t\tObservers Latitude. Positive to the west.\n");
351 printf("\t-lon <Longitude>\tObservers Longitude.\n");
352 printf("\t-td <Delta Time>\tUser defined difference between UT an LT (hours).\n");
353 printf("\t-h\t\t\tDisplay help screen.\n\n");
362 * This routine handles button presses. Clicking in the window
363 * toggles the display.
366 void pressEvent(XButtonEvent
*xev
){
369 if (ToggleWindow
> 4) ToggleWindow
= 0;