~ubuntu-branches/ubuntu/wily/wmmoonclock/wily

« back to all changes in this revision

Viewing changes to .pc/02_update_time.diff/Src/wmMoonClock.c

  • Committer: Bazaar Package Importer
  • Author(s): Denis Briand
  • Date: 2010-03-14 18:30:16 UTC
  • Revision ID: james.westby@ubuntu.com-20100314183016-88jc5ft5cbyfyd2h
Tags: 1.27-29
* Switch to dpkg-source 3.0 (quilt) format.
* Bump standards version to 3.8.4.
* Add ${misc:Depends} to the binary dependencies.
* Allow Debian maintainers uploads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *      wmMoonClock-1.26 (C) 1998, 1999 Mike Henderson (mghenderson@lanl.gov)
 
4
 * 
 
5
 *              - Shows Moon Phase....
 
6
 *          
 
7
 * 
 
8
 * 
 
9
 * 
 
10
 *
 
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)
 
14
 *      any later version.
 
15
 *
 
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.
 
20
 *
 
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
 
25
 *
 
26
 *      Things TODO:
 
27
 *                  - clean up code! 
 
28
 *                  - more detailed documentation.
 
29
 *                  - reduce size of pixmap! Dont need it in one pixmap.
 
30
 *                    Aslo, does the hi-color pixmap really need all those colors?
 
31
 *                  - add rotation of moon so user sees it as they would in reality?
 
32
 *                  - eclipses. The calcs are quite acurate so this should be easily doable.
 
33
 *                    (Note the Sun position calcs in CalcEphem are low precision -- high is not
 
34
 *                     as costly as the Moon calcs.) Sun posiiton is calculated but not used yet...
 
35
 *                  - Next new moons, next full moons, next quarters, etc...
 
36
 *                  - Moon names. I.e. Harvest, Blue, etc...
 
37
 *                  
 
38
 *                 
 
39
 *
 
40
 *      Changes:
 
41
 *      Version 1.27 -  released June 7, 1999.
 
42
 *                      fixed a minor bug in computation of azimuth (A in Horizon Coords). Thanks to
 
43
 *                      Dan Moraru for spotting this one. (There were two SinGlat factors instead of one).
 
44
 *
 
45
 *      Version 1.26 -  released April 22, 1999 (?).
 
46
 *      Version 1.25 -  released March 22, 1999.
 
47
 *                      Now auto-detects 8-bit display and forces the LowColor pixmap to
 
48
 *                      be used. The -low option still works if you need to conserve colors
 
49
 *                      even on high-color displays.
 
50
 *                      
 
51
 *                      Added 3 command line options + code to change colors of the data
 
52
 *                      entries:
 
53
 *                  
 
54
 *                              -bc <Color> to change background color.                  
 
55
 *                              -lc <Color> to change color of labels and headers.                  
 
56
 *                              -dc <Color> to change color of data values.
 
57
 *                  
 
58
 *      Version 1.24 -  released February 9, 1999.
 
59
 *                      Added low color support via the -low command line option.
 
60
 *                  
 
61
 *      Version 1.23 -  released February 4, 1999.
 
62
 *                      cosmetic for AfterStep users. removed spurious black line at RHS edge an mask.
 
63
 *
 
64
 *      Version 1.22 -  released January 8, 1999. 
 
65
 *
 
66
 *                      + Changed PI2 to TwoPi in Moon.c -- Linux Pyth. had probs because
 
67
 *                        PI2 was defined in <math.h>.
 
68
 *
 
69
 *      Version 1.21 -  released January 7, 1999. 
 
70
 *    
 
71
 *                     + minor bug fixes in Makefile and manpage.
 
72
 *
 
73
 *      Version 1.2 - released January 3, 1999. 
 
74
 *                    Added:
 
75
 *
 
76
 *                      + Local Time/ Universal Time display.
 
77
 *                      + Visible: Yes/No to indicate if Moon is up or not.
 
78
 *                      + Frac (percent through orbit -- this is NOT a simple
 
79
 *                        conversion of AGE....).
 
80
 *                      + Horizon Coords. Altitude is measured up from horizon to 
 
81
 *                        Moon in degrees. Azimuth is in degrees from due south.
 
82
 *                      
 
83
 *                    Also shuffled things around a bit...
 
84
 *                      
 
85
 *
 
86
 *
 
87
 *      Version 1.1 - released December 24, 1998. 
 
88
 *                    Fixed bug in AGE calculation. It now should be highly accurate.
 
89
 *                    Note that AGE is not the same as Phase*29.530589 ...
 
90
 *                    I have checked with the Astronomical Almanac and it agrees very
 
91
 *                    well....
 
92
 *
 
93
 *
 
94
 *      Version 1.0 - released December 16, 1998.
 
95
 *
 
96
 *
 
97
 *
 
98
 */
 
99
 
 
100
 
 
101
 
 
102
 
 
103
 
 
104
/*  
 
105
 *   Includes  
 
106
 */
 
107
#include <stdio.h>
 
108
#include <unistd.h>
 
109
#include <stdlib.h>
 
110
#include <string.h>
 
111
#include <time.h>
 
112
#include <X11/X.h>
 
113
#include <X11/xpm.h>
 
114
#include "CalcEphem.h"
 
115
#include "MoonRise.h"
 
116
#include "xutils.h"
 
117
#include "wmMoonClock_master.xpm"
 
118
#include "wmMoonClock_masterLow.xpm"
 
119
#include "wmMoonClock_mask.xbm"
 
120
 
 
121
 
 
122
 
 
123
/* 
 
124
 *  Delay between refreshes (in microseconds) 
 
125
 */
 
126
#define DELAY 1000000L
 
127
#define WMMOONCLOCK_VERSION "1.27"
 
128
 
 
129
 
 
130
 
 
131
 
 
132
 
 
133
void ParseCMDLine(int argc, char *argv[]);
 
134
void pressEvent(XButtonEvent *xev);
 
135
void print_usage();
 
136
 
 
137
 
 
138
int     ToggleWindow = 0;
 
139
int     nMAX = 1;
 
140
int     Flag = 1; 
 
141
double  Glat, Glon, SinGlat, CosGlat, TimeZone;
 
142
int     UseLowColorPixmap = 0;
 
143
char    LabelColor[30]    = "#a171ff";
 
144
char    DataColor[30]     = "#3dafff";
 
145
char    BackColor[30]     = "#010101";
 
146
 
 
147
 
 
148
 
 
149
 
 
150
 
 
151
 
 
152
/*  
 
153
 *   main  
 
154
 */
 
155
int main(int argc, char *argv[]) {
 
156
 
 
157
 
 
158
 
 
159
 
 
160
 
 
161
    struct tm           *GMTTime, *LocalTime;
 
162
    XEvent              event;
 
163
    int                 i, n, j, ImageNumber, Year, Month, DayOfMonth, digit;
 
164
    long                CurrentLocalTime, CurrentGMTTime, date;
 
165
    double              UT, val, RA, DEC, UTRise, UTSet, LocalHour, hour24();
 
166
    int                 D, H, M, S, sgn, A, B, q;
 
167
    CTrans              c;
 
168
    struct timeval      timeout;
 
169
    fd_set              xfdset;
 
170
 
 
171
 
 
172
 
 
173
 
 
174
 
 
175
  
 
176
    /*
 
177
     *  Parse any command line arguments.
 
178
     */
 
179
    Glat = Glon = 0.0;
 
180
    ParseCMDLine(argc, argv);
 
181
    c.Glat = Glat, c.Glon = Glon;
 
182
    Glat *= RadPerDeg; SinGlat = sin( Glat ); CosGlat = cos( Glat );
 
183
   
 
184
 
 
185
   
 
186
    initXwindow(argc, argv);
 
187
    if ((DisplayDepth <= 8)||UseLowColorPixmap)
 
188
        openXwindow(argc, argv, wmMoonClock_masterLow, wmMoonClock_mask_bits, wmMoonClock_mask_width, wmMoonClock_mask_height, BackColor, LabelColor, DataColor);
 
189
    else
 
190
        openXwindow(argc, argv, wmMoonClock_master, wmMoonClock_mask_bits, wmMoonClock_mask_width, wmMoonClock_mask_height, BackColor, LabelColor, DataColor);
 
191
 
 
192
 
 
193
 
 
194
 
 
195
   
 
196
    /*
 
197
     *  Loop until we die
 
198
     */
 
199
    n = 32000;
 
200
    while(1) {
 
201
 
 
202
 
 
203
        if (Flag) {
 
204
            n = 32000;
 
205
            Flag = 0;
 
206
        }
 
207
 
 
208
 
 
209
 
 
210
 
 
211
        /*
 
212
         *  The Moon Ephemeris calculations are somewhat costly (the Moon is one of the most
 
213
         *  difficult objects to compute position for). So only process every nMAXth cycle of this
 
214
         *  loop. We run outer loop it faster to catch expose events, button presses, etc...
 
215
         *
 
216
         */
 
217
        if (n>nMAX){
 
218
 
 
219
            n = 0;
 
220
 
 
221
            CurrentGMTTime = time(CurrentTime); GMTTime = gmtime(&CurrentGMTTime); 
 
222
            UT = GMTTime->tm_hour + GMTTime->tm_min/60.0 + GMTTime->tm_sec/3600.0;
 
223
            Year = GMTTime->tm_year+1900;
 
224
            Month = GMTTime->tm_mon+1;
 
225
            DayOfMonth = GMTTime->tm_mday;
 
226
            date = Year*10000 + Month*100 + DayOfMonth;
 
227
            CurrentLocalTime = CurrentGMTTime; LocalTime = localtime(&CurrentLocalTime);
 
228
            LocalHour = LocalTime->tm_hour + LocalTime->tm_min/60.0 + LocalTime->tm_sec/3600.0;
 
229
            TimeZone = UT - LocalHour;
 
230
 
 
231
 
 
232
            CalcEphem(date, UT, &c);
 
233
 
 
234
 
 
235
 
 
236
 
 
237
 
 
238
            if (ToggleWindow == 0){
 
239
 
 
240
                /*
 
241
                 *  Update Moon Image
 
242
                 */
 
243
 
 
244
                nMAX = 1000;
 
245
                ImageNumber = (int)(c.MoonPhase * 60.0 + 0.5);
 
246
                if (ImageNumber > 59) ImageNumber = 0;
 
247
                j = ImageNumber/10;
 
248
                i = ImageNumber%10;
 
249
                copyXPMArea(67+58*i, 2+58*j, 54, 54, 5, 5);
 
250
 
 
251
            } else if (ToggleWindow == 1){
 
252
 
 
253
                /*
 
254
                 *  Update Numerical Display
 
255
                 */
 
256
 
 
257
 
 
258
                nMAX = 500;
 
259
 
 
260
 
 
261
                /*
 
262
                 * Clear plotting area
 
263
                 */
 
264
                copyXPMArea(4, 69, 56, 56, 4, 4);
 
265
 
 
266
 
 
267
 
 
268
                /*
 
269
                 *  Paste up LT and UT. 
 
270
                 */
 
271
                val = LocalHour;
 
272
                H = (int)val; val = (val - H)*60.0;
 
273
                M = (int)val; val = (val - M)*60.0;
 
274
                S = (int)val;
 
275
                digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 25, 6);
 
276
                digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+5, 6);
 
277
                copyXPMArea(117, 353, 1, 6, 25+10, 6);
 
278
                digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 25+12, 6);
 
279
                digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+17, 6);
 
280
 
 
281
                val = UT;
 
282
                H = (int)val; val = (val - H)*60.0;
 
283
                M = (int)val; val = (val - M)*60.0;
 
284
                S = (int)val;
 
285
                digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 25, 15);
 
286
                digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+5, 15);
 
287
                copyXPMArea(117, 353, 1, 6, 25+10, 15);
 
288
                digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 25+12, 15);
 
289
                digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+17, 15);
 
290
 
 
291
 
 
292
 
 
293
 
 
294
 
 
295
                /*
 
296
                 *  Paste up AGE. 
 
297
                 */
 
298
                val = c.MoonAge;
 
299
                q = (val < 10.0) ? 5 : 0;
 
300
                A = (int)val;
 
301
                val = (val - A)*100.0;
 
302
                B = (int)val;
 
303
                digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 26-q, 24);
 
304
                digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 26+5-q, 24);
 
305
                copyXPMArea(62, 357, 3, 3, 26+11-q, 28);
 
306
                digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 26+15-q, 24);
 
307
                digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 26+20-q, 24);
 
308
                copyXPMArea(143, 354, 3, 3, 26+25-q, 23);
 
309
 
 
310
 
 
311
 
 
312
 
 
313
                /*
 
314
                 *  Paste up Phase (Percent Illuminated). 
 
315
                 */
 
316
                val = 0.5*( 1.0 - cos(c.MoonPhase*6.2831853) );
 
317
                val *= 100.0;
 
318
                A = (int)(val+0.5);
 
319
                if (A == 100){
 
320
                    copyXPMArea(72, 353, 5, 7, 32+5, 42);
 
321
                    copyXPMArea(67, 353, 5, 7, 32+10, 42);
 
322
                    copyXPMArea(67, 353, 5, 7, 32+15, 42);
 
323
                    copyXPMArea(147, 353, 5, 7, 32+20, 42);
 
324
                } else if (A >= 10){
 
325
                    digit = A/10; copyXPMArea(67+digit*5, 353, 5, 7, 32+5, 42);
 
326
                    digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 32+10, 42);
 
327
                    copyXPMArea(147, 353, 5, 7, 32+15, 42);
 
328
                } else {
 
329
                    digit = A; copyXPMArea(67+digit*5, 353, 5, 7, 32+5, 42);
 
330
                    copyXPMArea(147, 353, 5, 7, 32+10, 42);
 
331
                }
 
332
 
 
333
 
 
334
 
 
335
 
 
336
                /*
 
337
                 *  Paste up Frac (Percent of way through current lunar cycle). 
 
338
                 */
 
339
                val = c.MoonPhase*100.0;
 
340
                A = (int)(val+0.5);
 
341
                if (A == 100){
 
342
                    copyXPMArea(72, 353, 5, 7, 27+5, 33);
 
343
                    copyXPMArea(67, 353, 5, 7, 27+10, 33);
 
344
                    copyXPMArea(67, 353, 5, 7, 27+15, 33);
 
345
                    copyXPMArea(147, 353, 5, 7, 27+20, 33);
 
346
                } else if (A >= 10){
 
347
                    digit = A/10; copyXPMArea(67+digit*5, 353, 5, 7, 27+5, 33);
 
348
                    digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 27+10, 33);
 
349
                    copyXPMArea(147, 353, 5, 7, 27+15, 33);
 
350
                } else {
 
351
                    digit = A; copyXPMArea(67+digit*5, 353, 5, 7, 27+5, 33);
 
352
                    copyXPMArea(147, 353, 5, 7, 27+10, 33);
 
353
                }
 
354
 
 
355
 
 
356
                /*
 
357
                 *  Paste up Visible Status. 
 
358
                 */
 
359
                if (c.Visible)
 
360
                    copyXPMArea(6,  327, 13, 6, 46, 51);
 
361
                else
 
362
                    copyXPMArea(26, 327,  9, 6, 46, 51);
 
363
 
 
364
 
 
365
 
 
366
 
 
367
            } else if (ToggleWindow == 2){
 
368
 
 
369
                /*
 
370
                 *  Plot up Moon Rise/Set Times
 
371
                 */
 
372
 
 
373
 
 
374
                nMAX = 500;
 
375
 
 
376
                /*
 
377
                 * Clear plotting area
 
378
                 */
 
379
                copyXPMArea(4, 134, 56, 56, 4, 4);
 
380
 
 
381
 
 
382
                /*
 
383
                 *   Do Yesterday's first
 
384
                 */
 
385
                MoonRise(Year, Month, DayOfMonth-1, LocalHour, &UTRise, &UTSet); 
 
386
                UTTohhmm(UTRise, &H, &M); 
 
387
                if (H >= 0){
 
388
                    digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 19);
 
389
                    digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 19);
 
390
                    copyXPMArea(117, 354, 1, 4, 7+10, 20);
 
391
                    digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 19);
 
392
                    digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 19);
 
393
                } else {
 
394
                    copyXPMArea(57, 355, 5, 1, 7, 22); copyXPMArea(57, 355, 5, 1, 7+5, 22);
 
395
                    copyXPMArea(117, 354, 1, 4, 7+10, 20);
 
396
                    copyXPMArea(57, 355, 5, 1, 7+12, 22); copyXPMArea(57, 355, 5, 1, 7+17, 22);
 
397
                }
 
398
                UTTohhmm(UTSet, &H, &M); 
 
399
                if (H >= 0){
 
400
                    digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 19);
 
401
                    digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 19);
 
402
                    copyXPMArea(117, 354, 1, 4, 35+10, 20);
 
403
                    digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 19);
 
404
                    digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 19);
 
405
                } else {
 
406
                    copyXPMArea(57, 355, 5, 1, 35, 22); copyXPMArea(57, 355, 5, 1, 35+5, 22);
 
407
                    copyXPMArea(117, 354, 1, 4, 35+10, 20);
 
408
                    copyXPMArea(57, 355, 5, 1, 35+12, 22); copyXPMArea(57, 355, 5, 1, 35+17, 22);
 
409
                }
 
410
 
 
411
 
 
412
                /*
 
413
                 *  Plot up todays Rise/Set times.
 
414
                 */
 
415
                MoonRise(Year, Month, DayOfMonth,   LocalHour, &UTRise, &UTSet);
 
416
                UTTohhmm(UTRise, &H, &M); 
 
417
                if (H >= 0){
 
418
                    digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 29);
 
419
                    digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 29);
 
420
                    copyXPMArea(117, 354, 1, 4, 7+10, 30);
 
421
                    digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 29);
 
422
                    digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 29);
 
423
                } else {
 
424
                    copyXPMArea(57, 355, 5, 1, 7, 32); copyXPMArea(57, 355, 5, 1, 7+5, 32);
 
425
                    copyXPMArea(117, 354, 1, 4, 7+10, 30);
 
426
                    copyXPMArea(57, 355, 5, 1, 7+12, 32); copyXPMArea(57, 355, 5, 1, 7+17, 32);
 
427
                }
 
428
                UTTohhmm(UTSet, &H, &M); 
 
429
                if (H >= 0){
 
430
                    digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 29);
 
431
                    digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 29);
 
432
                    copyXPMArea(117, 354, 1, 4, 35+10, 30);
 
433
                    digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 29);
 
434
                    digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 29);
 
435
                } else {
 
436
                    copyXPMArea(57, 355, 5, 1, 35, 32); copyXPMArea(57, 355, 5, 1, 35+5, 32);
 
437
                    copyXPMArea(117, 354, 1, 4, 35+10, 30);
 
438
                    copyXPMArea(57, 355, 5, 1, 35+12, 32); copyXPMArea(57, 355, 5, 1, 35+17, 32);
 
439
                }
 
440
 
 
441
 
 
442
 
 
443
                /*
 
444
                 *  Plot up tomorrow's Rise/Set times.
 
445
                 */
 
446
                MoonRise(Year, Month, DayOfMonth+1, LocalHour, &UTRise, &UTSet);
 
447
                UTTohhmm(UTRise, &H, &M); 
 
448
                if (H >= 0){
 
449
                    digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 39);
 
450
                    digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 39);
 
451
                    copyXPMArea(117, 354, 1, 4, 7+10, 40);
 
452
                    digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 39);
 
453
                    digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 39);
 
454
                } else {
 
455
                    copyXPMArea(57, 355, 5, 1, 7, 42); copyXPMArea(57, 355, 5, 1, 7+5, 42);
 
456
                    copyXPMArea(117, 354, 1, 4, 7+10, 40);
 
457
                    copyXPMArea(57, 355, 5, 1, 7+12, 42); copyXPMArea(57, 355, 5, 1, 7+17, 42);
 
458
                }
 
459
                UTTohhmm(UTSet, &H, &M); 
 
460
                if (H >= 0){
 
461
                    digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 39);
 
462
                    digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 39);
 
463
                    copyXPMArea(117, 354, 1, 4, 35+10, 40);
 
464
                    digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 39);
 
465
                    digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 39);
 
466
                } else {
 
467
                    copyXPMArea(57, 355, 5, 1, 35, 42); copyXPMArea(57, 355, 5, 1, 35+5, 42);
 
468
                    copyXPMArea(117, 354, 1, 4, 35+10, 40);
 
469
                    copyXPMArea(57, 355, 5, 1, 35+12, 42); copyXPMArea(57, 355, 5, 1, 35+17, 42);
 
470
                }
 
471
 
 
472
 
 
473
            } else if (ToggleWindow == 3){
 
474
 
 
475
                /*
 
476
                 *  Plot up Horizon Coords
 
477
                 */
 
478
 
 
479
 
 
480
 
 
481
                nMAX = 500;
 
482
 
 
483
                /*
 
484
                 * Clear plotting area
 
485
                 */
 
486
                copyXPMArea(4, 199, 56, 56, 4, 4);
 
487
 
 
488
 
 
489
 
 
490
                /*
 
491
                 *  Paste up Azimuth, A
 
492
                 */
 
493
                val = c.A_moon;
 
494
                sgn = (val < 0.0) ? -1 : 0;
 
495
                val = fabs(val);
 
496
                D = (int)val;
 
497
                val = (val-(double)D)*100.0;
 
498
                M = (int)val;
 
499
                
 
500
                if (sgn < 0) copyXPMArea(120, 357, 2, 1, 19, 27);
 
501
 
 
502
                /* degrees 100's */
 
503
                digit = D/100; copyXPMArea(67+digit*5, 353, 5, 7, 22, 24);
 
504
                D -= digit*100;
 
505
 
 
506
                /* degrees 10's */
 
507
                digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+5, 24);
 
508
 
 
509
                /* degrees 1's */
 
510
                digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+10, 24);
 
511
 
 
512
                /* Decimal */
 
513
                copyXPMArea(62, 357, 3, 3, 22+15, 28);
 
514
 
 
515
                /*  Decimal Part */
 
516
                digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+19, 24);
 
517
 
 
518
                /*  mins 1's */
 
519
                digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+24, 24);
 
520
 
 
521
                copyXPMArea(120, 353, 3, 3, 22+29, 23);
 
522
 
 
523
 
 
524
 
 
525
 
 
526
 
 
527
                /*
 
528
                 *  Paste up Altitude, h
 
529
                 */
 
530
                val = c.h_moon;
 
531
                sgn = (val < 0.0) ? -1 : 0;
 
532
                val = fabs(val);
 
533
                D = (int)val;
 
534
                val = (val-(double)D)*100.0;
 
535
                M = (int)val;
 
536
                
 
537
                if (sgn < 0) copyXPMArea(120, 357, 2, 1, 19, 39);
 
538
 
 
539
                /* degrees 10's */
 
540
                digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 22, 36);
 
541
 
 
542
                /* degrees 1's */
 
543
                digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+5, 36);
 
544
 
 
545
                /* Decimal */
 
546
                copyXPMArea(62, 357, 3, 3, 22+10, 40);
 
547
 
 
548
                /*  Decimal Part */
 
549
                digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+14, 36);
 
550
 
 
551
                /*  mins 1's */
 
552
                digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+19, 36);
 
553
 
 
554
                copyXPMArea(120, 353, 3, 3, 22+24, 35);
 
555
 
 
556
 
 
557
 
 
558
 
 
559
 
 
560
                /*
 
561
                 *  Paste up Earth-Moon Distance (in units of Earth radii). 
 
562
                 */
 
563
                val = c.EarthMoonDistance;
 
564
                A = (int)val;
 
565
                val = (val - A)*100.0;
 
566
                B = (int)val;
 
567
                digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 30, 47);
 
568
                digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+5, 47);
 
569
                copyXPMArea(62, 357, 3, 3, 30+11, 51);
 
570
                digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 30+15, 47);
 
571
                digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+20, 47);
 
572
 
 
573
 
 
574
 
 
575
            } else if (ToggleWindow == 4){
 
576
 
 
577
                /*
 
578
                 *  Plot up RA/DEC Coords
 
579
                 */
 
580
 
 
581
 
 
582
 
 
583
                nMAX = 500;
 
584
 
 
585
                /*
 
586
                 * Clear plotting area
 
587
                 */
 
588
                copyXPMArea(4, 264, 56, 56, 4, 4);
 
589
 
 
590
 
 
591
 
 
592
                /*
 
593
                 *  Paste up Right Ascention
 
594
                 */
 
595
                RA = c.RA_moon/15.0;
 
596
                H = (int)RA;
 
597
                RA = (RA-(double)H)*60.0;
 
598
                M = (int)RA; RA = (RA-(double)M)*60.0;
 
599
                S = (int)(RA+0.5);
 
600
                
 
601
                /* hours 10's */
 
602
                digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 17, 25);
 
603
 
 
604
                /* hours 1's */
 
605
                digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+5, 25);
 
606
 
 
607
                /* hour symbol */
 
608
                copyXPMArea(138, 354, 3, 3, 17+10, 24);
 
609
 
 
610
                /*  mins 10's */
 
611
                digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+14, 25);
 
612
 
 
613
                /*  mins 1's */
 
614
                digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+19, 25);
 
615
 
 
616
                /* min symbol */
 
617
                copyXPMArea(124, 353, 3, 3, 17+23, 24);
 
618
 
 
619
                /*  secs 10's */
 
620
                digit = S/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+27, 25);
 
621
 
 
622
                /*  secs 1's */
 
623
                digit = S%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+32, 25);
 
624
 
 
625
                /* sec symbol */
 
626
                copyXPMArea(128, 353, 5, 3, 17+36, 24);
 
627
 
 
628
 
 
629
 
 
630
 
 
631
                /*
 
632
                 *  Paste up Declination
 
633
                 */
 
634
                DEC = c.DEC_moon;
 
635
                sgn = (DEC < 0.0) ? -1 : 0;
 
636
                DEC = fabs(DEC);
 
637
                D = (int)DEC;
 
638
                DEC = (DEC-(double)D)*60.0;
 
639
                M = (int)DEC;
 
640
                DEC = (DEC-(double)M)*60.0;
 
641
                S = (int)(DEC+0.5);
 
642
                
 
643
                if (sgn < 0) copyXPMArea(120, 357, 2, 1, 14, 39);
 
644
 
 
645
 
 
646
                /* degrees 10's */
 
647
                digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 17, 36);
 
648
 
 
649
                /* degrees 1's */
 
650
                digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+5, 36);
 
651
 
 
652
                /* degree symbol */
 
653
                copyXPMArea(120, 353, 3, 3, 17+10, 35);
 
654
 
 
655
                /*  mins 10's */
 
656
                digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+14, 36);
 
657
 
 
658
                /*  mins 1's */
 
659
                digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+19, 36);
 
660
 
 
661
                /* min symbol */
 
662
                copyXPMArea(124, 353, 3, 3, 17+23, 35);
 
663
 
 
664
                /*  secs 10's */
 
665
                digit = S/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+27, 36);
 
666
 
 
667
                /*  secs 1's */
 
668
                digit = S%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+32, 36);
 
669
 
 
670
                /* sec symbol */
 
671
                copyXPMArea(128, 353, 5, 3, 17+36, 35);
 
672
 
 
673
 
 
674
 
 
675
 
 
676
                /*
 
677
                 *  Paste up Earth-Moon Distance (in units of Earth radii). 
 
678
                 */
 
679
                val = c.EarthMoonDistance;
 
680
                A = (int)val;
 
681
                val = (val - A)*100.0;
 
682
                B = (int)val;
 
683
                digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 30, 47);
 
684
                digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+5, 47);
 
685
                copyXPMArea(62, 357, 3, 3, 30+11, 51);
 
686
                digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 30+15, 47);
 
687
                digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+20, 47);
 
688
 
 
689
 
 
690
 
 
691
            } 
 
692
 
 
693
 
 
694
 
 
695
        } else {
 
696
 
 
697
            /*
 
698
             *  Update the counter. 
 
699
             */
 
700
            ++n;
 
701
 
 
702
        }
 
703
 
 
704
 
 
705
 
 
706
 
 
707
 
 
708
        /*
 
709
         *  Add X display to file descriptor set for polling.
 
710
         */
 
711
        FD_ZERO(&xfdset);
 
712
        FD_SET(ConnectionNumber(display), &xfdset);
 
713
 
 
714
 
 
715
 
 
716
        /* 
 
717
         *   Process any pending X events.
 
718
         */
 
719
        while(XPending(display)){
 
720
            XNextEvent(display, &event);
 
721
            switch(event.type){
 
722
                case Expose:
 
723
                        RedrawWindow();
 
724
                        break;
 
725
                case ButtonPress:
 
726
                        pressEvent(&event.xbutton);
 
727
                        break;
 
728
                case ButtonRelease:
 
729
                        break;
 
730
            }
 
731
        }
 
732
 
 
733
 
 
734
 
 
735
 
 
736
 
 
737
        
 
738
        /* 
 
739
         *  Redraw and wait for next update 
 
740
         */
 
741
        RedrawWindow();
 
742
        timeout.tv_sec = DELAY / 1000000L;
 
743
        timeout.tv_usec = DELAY % 1000000L;
 
744
        select(ConnectionNumber(display) + 1, &xfdset, NULL, NULL, &timeout);
 
745
 
 
746
 
 
747
     }
 
748
 
 
749
 
 
750
 
 
751
}
 
752
 
 
753
 
 
754
 
 
755
 
 
756
 
 
757
 
 
758
 
 
759
 
 
760
/* 
 
761
 *   ParseCMDLine()  
 
762
 */
 
763
void ParseCMDLine(int argc, char *argv[]) {
 
764
 
 
765
    int  i;
 
766
    char *eptr;
 
767
  
 
768
    for (i = 1; i < argc; i++) {
 
769
 
 
770
        if (!strcmp(argv[i], "-display")){
 
771
 
 
772
            ++i;
 
773
 
 
774
        } else if (!strcmp(argv[i], "-bc")){
 
775
 
 
776
            if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
 
777
                fprintf(stderr, "wmMoonClock: -bc needs a color argument.\n");
 
778
                print_usage();
 
779
                exit(-1);
 
780
            }
 
781
            strcpy(BackColor, argv[++i]);
 
782
 
 
783
        } else if (!strcmp(argv[i], "-lc")){
 
784
 
 
785
            if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
 
786
                fprintf(stderr, "wmMoonClock: -lc needs a color argument.\n");
 
787
                print_usage();
 
788
                exit(-1);
 
789
            }
 
790
            strcpy(LabelColor, argv[++i]);
 
791
 
 
792
        } else if (!strcmp(argv[i], "-dc")){
 
793
 
 
794
            if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
 
795
                fprintf(stderr, "wmMoonClock: -dc needs a color argument.\n");
 
796
                print_usage();
 
797
                exit(-1);
 
798
            }
 
799
            strcpy(DataColor, argv[++i]);
 
800
 
 
801
        } else if (!strcmp(argv[i], "-low")){
 
802
 
 
803
            UseLowColorPixmap = 1;
 
804
 
 
805
        } else if (!strcmp(argv[i], "-lat")){
 
806
 
 
807
            if (i+1 >= argc){
 
808
                fprintf(stderr, "wmMoonClock: -lat needs a value in degrees.\n");
 
809
                print_usage();
 
810
                exit(-1);
 
811
            } else {
 
812
                Glat = strtod(argv[i+1], &eptr);
 
813
                if ((Glat == 0.0)&&(eptr == argv[i+1])){
 
814
                    fprintf(stderr, "wmMoonClock: could not convert latitude %s.\n", argv[i+1]);
 
815
                    print_usage();
 
816
                    exit(-1);
 
817
                }
 
818
                ++i;
 
819
            }
 
820
 
 
821
        } else if (!strcmp(argv[i], "-lon")){
 
822
 
 
823
            if (i+1 >= argc){
 
824
                fprintf(stderr, "wmMoonClock: -lat needs a value in degrees.\n");
 
825
                print_usage();
 
826
                exit(-1);
 
827
            } else {
 
828
                Glon = strtod(argv[i+1], &eptr);
 
829
                if ((Glon == 0.0)&&(eptr == argv[i+1])){
 
830
                    fprintf(stderr, "wmMoonClock: could not convert longitude %s.\n", argv[i+1]);
 
831
                    print_usage();
 
832
                    exit(-1);
 
833
                }
 
834
                ++i;
 
835
            }
 
836
 
 
837
        } else {
 
838
            
 
839
            print_usage();
 
840
            exit(1);
 
841
        }
 
842
    }
 
843
 
 
844
}
 
845
 
 
846
 
 
847
void print_usage(){
 
848
 
 
849
    printf("\nwmMoonClock version: %s\n", WMMOONCLOCK_VERSION);
 
850
    printf("\nusage: wmMoonClock [-display <Display>] [-lat <Latitude>] [-lon <Longitude>] [-h]\n");
 
851
    printf("                   [-bc <Color>] [-lc <Color>] [-dc <Color>]\n\n");
 
852
    printf("\t-display <Display>\tUse alternate X display.\n");
 
853
    printf("\t-bc <Color>   \t\tBackground color. (e.g. #ffbb00 or orange)\n");
 
854
    printf("\t-lc <Color>   \t\tColor for lables.\n");
 
855
    printf("\t-dc <Color>   \t\tColor for data entries.\n");
 
856
    printf("\t-low           \t\tUse lower color pixmap (for 8-bit displays).\n");
 
857
    printf("\t-lat <Latitude>\t\tObservers Latitude. Positive in northern\n");
 
858
    printf("\t               \t\themisphere, negative in southern hemisphere.\n");
 
859
    printf("\t-lon <Longitude>\tObservers Longitude. Greenwich is 0.0, and longitude\n");
 
860
    printf("\t                \tincreases positively toward the west. (Alternatively,\n");
 
861
    printf("\t                \tnegative numbers can also be used to specify\n");
 
862
    printf("\t                \tlongitudes to the east of Greenwich).\n");
 
863
    printf("\t-h\t\t\tDisplay help screen.\n\n");
 
864
 
 
865
}
 
866
 
 
867
 
 
868
/*
 
869
 *  This routine handles button presses. Clicking in the window
 
870
 *  toggles the display.
 
871
 *
 
872
 */
 
873
void pressEvent(XButtonEvent *xev){
 
874
 
 
875
   ++ToggleWindow;
 
876
   if (ToggleWindow > 4) ToggleWindow = 0;
 
877
   Flag = 1;
 
878
 
 
879
   return;
 
880
 
 
881
}
 
882