-
Notifications
You must be signed in to change notification settings - Fork 3
/
skycalendar.c
2078 lines (1792 loc) · 59.7 KB
/
skycalendar.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This is a self-contained c-language program to print a nighttime
astronomical calendar for use in planning observations.
It prints to standard output (usually the terminal); the
operator should capture this output (e. g., using redirection
in UNIX or the /out= switch in VMS) and then print it on an
appropriate output device. The table which is printed is some
125 columns wide, so a wide device is required (either a line
printer or a laserprinter in LANDSCAPE mode.) It is assumed that
the ASCII form-feed character will actually begin a new page.
The original program was to run on VMS, but it should be very
transportable. Non-vms users will probably want to change
'unixio.h' to 'stdio.h' in the first line.
An explanatory text is printed at the beginning of the output, which
includes the appropriate CAUTIONS regarding accuracy and applicability.
A number of 'canned site' parameters have been included. Be
careful of time zones, DST etc. for foreign sites.
To customize to your own site, install an option in the
routine 'load_site'. The code is very straightforward; just do
it exactly the same as the others. You might also want to erase
some seldom-used choices. One can also specify new site parameters
at run time.
This program may be used freely by anyone for scientific or educational
purposes. If you use it for profit, I want a cut, and claim
a copyright herewith. In any case please acknowledge the source:
John Thorstensen
Dept. of Physics and Astronomy
Dartmouth College
Hanover, NH 03755
John.Thorstensen@dartmouth.edu
May 26, 1993.
*/
#include <stdio.h>
#include <math.h>
double pi = 3.14159265358979;
#define PI 3.14159265358979
#define ARCSEC_IN_RADIAN 206264.8062
#define DEG_IN_RADIAN 57.2957795130823
#define HRS_IN_RADIAN 3.819718634
#define J2000 2451545.
#define SEC_IN_DAY 86400.
#define FLATTEN 0.003352813
#define EQUAT_RAD 6378137.
#define TWILIGHT_ALT -18.
struct coord
{
short sign; /* carry sign explicitly since -0 not neg. */
double hh;
double mm;
double ss;
};
struct coord_pair
{
struct coord RA;
struct coord dec;
};
double bab_to_dec (bab)
struct coord bab;
{
double x;
x = bab.sign * (bab.hh + bab.mm / 60. + bab.ss / 3600.);
return(x);
}
void dec_to_bab (deci,bab)
/* function for converting decimal to babylonian hh mm ss.ss */
double deci;
struct coord *bab;
{
int hr_int, min_int;
if (deci >= 0.) bab->sign = 1;
else {
bab->sign = -1;
deci = -1. * deci;
}
hr_int = deci; /* use conversion conventions to truncate */
bab->hh = hr_int;
min_int = 60. * (deci - bab->hh);
bab->mm = min_int;
bab->ss = 3600. * (deci - bab->hh - bab->mm / 60.);
}
double get_coord()
/* Reads a string from the terminal and converts it into
a double-precision coordinate. This is trickier than
it appeared at first, since a -00 tests as non-negative;
the sign has to be picked out and handled explicitly. */
/* Prompt for input in the calling routine.*/
{
short sign;
double hrs, mins, secs;
char hh_string[6]; /* string with the first coord (hh) */
char hh1[1];
short i = 0;
/* read and handle the hour (or degree) part with sign */
scanf("%s",hh_string);
hh1[0] = hh_string[i];
while(hh1[0] == ' ') {
/* discard leading blanks */
i++;
hh1[0] = hh_string[i];
}
if(hh1[0] == '-') sign = -1;
else sign = 1;
sscanf(hh_string,"%lf", &hrs);
if(sign == -1) hrs = -1. * hrs;
/* read in the minutes and seconds normally */
scanf("%lf %lf",&mins,&secs);
return(sign * (hrs + mins / 60. + secs / 3600.));
}
void put_coords(deci, precision)
double deci; /* decimal coordinate */
short precision;
/* prints out a struct coord in a nice format; precision
is a code for how accurate you want it. The options are:
precision = 0; minutes rounded to the nearest minute
precision = 1; minutes rounded to the nearest tenth.
precision = 2; seconds rounded to the nearest second
precision = 3; seconds given to the tenth
precision = 4; seconds given to the hundredth
The program assumes that the line is ready for the coord
to be printed and does NOT deliver a new line at the end
of the output. */
{
double minutes; /* for rounding off if necess. */
struct coord out_coord, coords;
char out_string[20]; /* for checking for nasty 60's */
dec_to_bab(deci,&coords); /* internally convert to coords*/
if(coords.sign == -1) printf("-");
else printf(" "); /* to preserve alignment */
if(precision == 0) { /* round to nearest minute */
minutes = coords.mm + coords.ss / 60.;
/* check to be sure minutes aren't 60 */
sprintf(out_string,"%.0f %02.0f",coords.hh,minutes);
sscanf(out_string,"%lf %lf",&out_coord.hh,&out_coord.mm);
if(fabs(out_coord.mm - 60.) < 1.0e-7) {
out_coord.mm = 0.;
out_coord.hh = out_coord.hh + 1.;
}
printf("%2.0f %02.0f",out_coord.hh,out_coord.mm);
}
else if(precision == 1) { /* keep nearest tenth of a minute */
minutes = coords.mm + coords.ss / 60.;
/* check to be sure minutes are not 60 */
sprintf(out_string,"%.0f %04.1f",coords.hh,minutes);
sscanf(out_string,"%lf %lf",&out_coord.hh, &out_coord.mm);
if(fabs(out_coord.mm - 60.) < 1.0e-7) {
out_coord.mm = 0.;
out_coord.hh = out_coord.hh + 1.;
}
printf("%2.0f %04.1f", out_coord.hh, out_coord.mm);
}
else if(precision == 2) {
/* check to be sure seconds are not 60 */
sprintf(out_string,"%.0f %02.0f %02.0f",coords.hh,coords.mm,coords.ss);
sscanf(out_string,"%lf %lf %lf",&out_coord.hh,&out_coord.mm,
&out_coord.ss);
if(fabs(out_coord.ss - 60.) < 1.0e-7) {
out_coord.mm = out_coord.mm + 1.;
out_coord.ss = 0.;
if(fabs(out_coord.mm - 60.) < 1.0e-7) {
out_coord.hh = out_coord.hh + 1.;
out_coord.mm = 0.;
}
}
printf("%2.0f %02.0f %02.0f",out_coord.hh,out_coord.mm,out_coord.ss);
}
else if(precision == 3) {
/* the usual shuffle to check for 60's */
sprintf(out_string,"%.0f %02.0f %04.1f",coords.hh, coords.mm, coords.ss);
sscanf(out_string,"%lf %lf %lf",&out_coord.hh,&out_coord.mm,
&out_coord.ss);
if(fabs(out_coord.ss - 60.) < 1.0e-7) {
out_coord.mm = out_coord.mm + 1.;
out_coord.ss = 0.;
if(fabs(out_coord.mm - 60.) < 1.0e-7) {
out_coord.hh = out_coord.hh + 1.;
out_coord.mm = 0.;
}
}
printf("%2.0f %02.0f %04.1f",out_coord.hh,out_coord.mm,out_coord.ss);
}
else {
sprintf(out_string,"%.0f %02.0f %05.2f",coords.hh,coords.mm,coords.ss);
sscanf(out_string,"%lf %lf %lf",&out_coord.hh,&out_coord.mm,
&out_coord.ss);
if(fabs(out_coord.ss - 60.) < 1.0e-6) {
out_coord.mm = out_coord.mm + 1.;
out_coord.ss = 0.;
if(fabs(out_coord.mm - 60.) < 1.0e-6) {
out_coord.hh = out_coord.hh + 1.;
out_coord.mm = 0.;
}
}
printf("%2.0f %02.0f %05.2f",out_coord.hh, out_coord.mm, out_coord.ss);
}
}
double atan_circ(x,y)
double x, y;
{
/* returns radian angle 0 to 2pi for coords x, y */
double theta;
if(x == 0) {
if(y > 0.) theta = PI/2.;
else if(y < 0.) theta = 3.*PI/2.;
else theta = 0.; /* x and y zero */
}
else theta = atan(y/x);
if(x < 0.) theta = theta + PI;
if(theta < 0.) theta = theta + 2.*PI;
return(theta);
}
double altit(dec,ha,lat)
double dec,ha,lat; /* dec deg, dec hrs, dec deg */
{
double x;
dec = dec / DEG_IN_RADIAN;
ha = ha / HRS_IN_RADIAN;
lat = lat / DEG_IN_RADIAN; /* thank heavens for pass-by-value */
x = DEG_IN_RADIAN * asin(cos(dec)*cos(ha)*cos(lat) + sin(dec)*sin(lat));
return(x);
}
void min_max_alt(lat,dec,min,max)
double lat, dec, *min, *max;
{
/* computes minimum and maximum altitude for a given dec and
latitude. */
double x;
lat = lat / DEG_IN_RADIAN; /* pass by value! */
dec = dec / DEG_IN_RADIAN;
x = cos(dec)*cos(lat) + sin(dec)*sin(lat);
if(fabs(x) <= 1.) {
*max = asin(x) * DEG_IN_RADIAN;
}
else printf("Error in min_max_alt -- arcsin(>1)\n");
x = sin(dec)*sin(lat) - cos(dec)*cos(lat);
if(fabs(x) <= 1.) {
*min = asin(x) * DEG_IN_RADIAN;
}
else printf("Error in min_max_alt -- arcsin(>1)\n");
}
double ha_alt(dec,lat,alt)
double dec,lat,alt; /* dec deg */
{
/* returns hour angle at which object at dec is at altitude alt */
double x,coalt,min,max;
min_max_alt(lat,dec,&min,&max);
if(alt < min)
return(1000.); /* flag value - always higher than asked */
if(alt > max)
return(-1000.); /* flag for object always lower than asked */
dec = (0.5*PI) - dec / DEG_IN_RADIAN;
lat = (0.5*PI) - lat / DEG_IN_RADIAN;
coalt = (0.5*PI) - alt / DEG_IN_RADIAN;
x = (cos(coalt) - cos(dec)*cos(lat)) / (sin(dec)*sin(lat));
if(fabs(x) <= 1.) return(acos(x) * HRS_IN_RADIAN);
else {
printf("Error in ha_alt ... acos(>1).\n");
return(1000.);
}
}
double subtend(ra1,dec1,ra2,dec2)
double ra1, dec1, ra2, dec2; /* dec hrs and dec degrees */
{
/* angle subtended by two directions in the sky. */
double x1, y1, z1, x2, y2, z2;
double theta;
ra1 = ra1 / HRS_IN_RADIAN;
dec1 = dec1 / DEG_IN_RADIAN;
ra2 = ra2 / HRS_IN_RADIAN;
dec2 = dec2 / DEG_IN_RADIAN;
x1 = cos(ra1)*cos(dec1);
y1 = sin(ra1)*cos(dec1);
z1 = sin(dec1);
x2 = cos(ra2)*cos(dec2);
y2 = sin(ra2)*cos(dec2);
z2 = sin(dec2);
theta = acos(x1*x2+y1*y2+z1*z2);
return(theta);
}
struct date_time
{
short y;
short mo;
short d;
short h;
short mn;
float s;
};
double date_to_jd(date)
struct date_time date;
{
short yr1=0, mo1=1;
long jdzpt = 1720982, jdint, inter;
double jd,jdfrac;
if((date.y <= 1900) | (date.y >= 2100)) {
printf("Date out of range. 1900 - 2100 only.\n");
return(0.);
}
if(date.mo <= 2) {
yr1 = -1;
mo1 = 13;
}
jdint = 365.25*(date.y+yr1); /* truncates */
inter = 30.6001*(date.mo+mo1);
jdint = jdint+inter+date.d+jdzpt;
jd = jdint;
jdfrac=date.h/24.+date.mn/1440.+date.s/86400;
if(jdfrac < 0.5) {
jdint--;
jdfrac=jdfrac+0.5;
}
else jdfrac=jdfrac-0.5;
jd=jdint+jdfrac;
return(jd);
}
void caldat(jdin,date)
#define IGREG 2299161
double jdin;
struct date_time *date;
{
/* Returns date and time for a given julian date;
Adapted from Numerical Recipes, p. 12. */
int mm, id, iyyy; /* their notation */
long ja, jdint, jalpha, jb, jc, jd, je;
float jdfrac;
jdin = jdin + 0.5; /* adjust for 1/2 day */
jdint = jdin;
jdfrac = jdin - jdint;
date->h = jdfrac * 24; /* truncate */
date->mn = (jdfrac - ((float) date->h)/24.) * 1440.;
date->s = (jdfrac - ((float) date->h)/24. -
((float) date->mn)/1440.) * 86400;
if(jdint > IGREG) {
jalpha=((float) (jdint-1867216)-0.25)/36524.25;
ja=jdint+1+jalpha-(long)(0.25*jalpha);
}
else
ja=jdint;
jb=ja+1524;
jc=6680.0+((float) (jb-2439870)-122.1)/365.25;
jd=365*jc+(0.25*jc);
je=(jb-jd)/30.6001;
id=jb-jd-(int) (30.6001*je);
mm=je-1;
if(mm > 12) mm -= 12;
iyyy=jc-4715;
if(mm > 2) --iyyy;
if (iyyy <= 0) --iyyy;
date->y = iyyy;
date->mo = mm;
date->d = id;
}
void print_calendar(jdin,length)
double jdin;
short length;
{
struct date_time date;
char *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
char mo_out[4];
caldat(jdin,&date);
mo_out[0] = *(months + 3*(date.mo - 1));
mo_out[1] = *(months + 3*(date.mo - 1) + 1);
mo_out[2] = *(months + 3*(date.mo - 1) + 2);
mo_out[3] = '\0';
if(length == 1)
printf("%d %s %d",date.y,mo_out,date.d);
else printf("%s %02d",mo_out,date.d); /*no year */
}
void print_time(jdin,prec)
double jdin;
short prec;
{
/* prints time only */
struct date_time date;
double temptime;
caldat(jdin,&date);
temptime = date.h + date.mn/60. + date.s/3600.;
put_coords(temptime,prec);
}
short day_of_week(jd)
double jd;
{
/* returns day of week, 0 = Mon, 6 = Sun. */
double x,y;
long i;
short d;
x = (jd+0.5)/7.;
d = 7.*(x - (long) x); /* truncate */
return(d);
}
void print_day(d)
short d;
{
char *days = "MonTueWedThuFriSatSun";
char day_out[4];
day_out[0] = *(days+3*d);
day_out[1] = *(days+3*d+1);
day_out[2] = *(days+3*d+2);
day_out[3] = '\0'; /* terminate with null char */
printf("%s",day_out);
}
double lst(jd,longit)
double jd,longit;
{
/* returns the local MEAN sidereal time (dec hrs) at julian date jd
at west longitude long (decimal hours). Follows
definitions in 1992 Astronomical Almanac, pp. B7 and L2.
Expression for GMST at 0h ut referenced to Aoki et al, A&A 105,
p.359, 1982. */
double t, ut, jdmid, jdint, jdfrac, sid_g, sid;
double jdnoon2000jan1 = 2451545.;
long jdin, sid_int;
jdin = jd; /* fossil code from earlier package which
split jd into integer and fractional parts ... */
jdint = jdin;
jdfrac = jd - jdint;
if(jdfrac < 0.5) {
jdmid = jdint - 0.5;
ut = jdfrac + 0.5;
}
else {
jdmid = jdint + 0.5;
ut = jdfrac - 0.5;
}
t = (jdmid - jdnoon2000jan1)/36525;
sid_g = (24110.54841+8640184.812866*t+0.093104*t*t-6.2e-6*t*t*t)/86400.;
sid_int = sid_g;
sid_g = sid_g - (double) sid_int;
sid_g = sid_g + 1.0027379093 * ut - longit/24.;
sid_int = sid_g;
sid_g = (sid_g - (double) sid_int) * 24.;
if(sid_g < 0.) sid_g = sid_g + 24.;
return(sid_g);
}
double adj_time(x)
double x;
{
/* adjusts a time (decimal hours) to be between -12 and 12. */
if(fabs(x) < 100000.) { /* too inefficient for this! */
while(x > 12.) {
x = x - 24.;
}
while(x < -12.) {
x = x + 24.;
}
}
else printf("Out of bounds in adj_time!\n");
return(x);
}
double circulo(x)
double x;
{
/* assuming x is an angle in degrees, returns
modulo 360 degrees. */
int n;
n = (int)(x / 360.);
return(x - 360. * n);
}
void geocent(geolong, geolat, height, x_geo, y_geo, z_geo)
double geolong, geolat, height, *x_geo, *y_geo, *z_geo;
/* computes the geocentric coordinates from the geodetic
(standard map-type) longitude, latitude, and height.
These are assumed to be in decimal hours, decimal degrees, and
meters respectively. Notation generally follows 1992 Astr Almanac,
p. K11 */
{
double denom, C_geo, S_geo;
geolat = geolat / DEG_IN_RADIAN;
geolong = geolong / HRS_IN_RADIAN;
denom = (1. - FLATTEN) * sin(geolat);
denom = cos(geolat) * cos(geolat) + denom*denom;
C_geo = 1. / sqrt(denom);
S_geo = (1. - FLATTEN) * (1. - FLATTEN) * C_geo;
C_geo = C_geo + height / EQUAT_RAD; /* deviation from almanac
notation -- include height here. */
S_geo = S_geo + height / EQUAT_RAD;
*x_geo = C_geo * cos(geolat) * cos(geolong);
*y_geo = C_geo * cos(geolat) * sin(geolong);
*z_geo = S_geo * sin(geolat);
}
void eclrot(jd, x, y, z)
/* rotates ecliptic rectangular coords x, y, z to
equatorial (all assumed of date.) */
double jd, *x, *y, *z;
{
double incl;
double xpr,ypr,zpr;
double T;
T = (jd - J2000) / 36525; /* centuries since J2000 */
incl = (23.439291 + T * (-0.0130042 - 0.00000016 * T))/DEG_IN_RADIAN;
/* 1992 Astron Almanac, p. B18, dropping the
cubic term, which is 2 milli-arcsec! */
ypr = cos(incl) * *y - sin(incl) * *z;
zpr = sin(incl) * *y + cos(incl) * *z;
*y = ypr;
*z = zpr;
/* x remains the same. */
}
double etcorr(jd)
double jd;
{
/* Given a julian date in 1900-2100, returns the jd corrected
for delta t; delta t is
TDT - UT (after 1983 and before 1994)
ET - UT (before 1983)
an extrapolated guess (after 1994).
For dates in the past (<= 1994 and after 1900) the value is linearly
interpolated on 5-year intervals; for dates after the present,
an extrapolation is used, because the true value of delta t
cannot be predicted precisely. Note that TDT is essentially the
modern version of ephemeris time with a slightly cleaner
definition.
Where the algorithm shifts there is an approximately 0.1 second
discontinuity. Also, the 5-year linear interpolation scheme can
lead to errors as large as 0.5 seconds in some cases, though
usually rather smaller. */
double jd1900 = 2415019.5;
double dates[20];
double delts[20]; /* can't initialize this look-up table
with stupid old sun compiler .... */
double year, delt;
int i;
/* this stupid patch for primitive sun C compilers ....
do not allow automatic initialization of arrays! */
for(i = 0; i <= 18; i++) dates[i] = 1900 + (double) i * 5.;
dates[19] = 1994;
delts[0] = -2.72; delts[1] = 3.86; delts[2] = 10.46;
delts[3] = 17.20; delts[4] = 21.16; delts[5] = 23.62;
delts[6] = 24.02; delts[7] = 23.93; delts[8] = 24.33;
delts[9] = 26.77; delts[10] = 29.15; delts[11] = 31.07;
delts[12] = 33.15; delts[13] = 35.73; delts[14] = 40.18;
delts[15] = 45.48; delts[16] = 50.54; delts[17] = 54.34;
delts[18] = 56.86; delts[19] = 59.98;
year = 1900. + (jd - 2415019.5) / 365.25;
if(year < 1994.0 && year >= 1900.) {
i = (year - 1900) / 5;
delt = delts[i] +
((delts[i+1] - delts[i])/(dates[i+1] - dates[i])) * (year - dates[i]);
}
else if (year > 1994. && year < 2100.)
delt = 33.15 + (2.164e-3) * (jd - 2436935.4); /* rough extrapolation */
else if (year < 1900) {
printf("etcorr ... no ephemeris time data for < 1900.\n");
delt = 0.;
}
else if (year >= 2100.) {
printf("etcorr .. very long extrapolation in delta T - inaccurate.\n");
delt = 180.; /* who knows? */
}
return(jd + delt/SEC_IN_DAY);
}
void accumoon(jd,geolat,lst,elevsea,topora,topodec,topodist)
double jd,geolat,lst,elevsea; /* jd, dec. degr., dec. hrs., meters */
double *topora,*topodec,*topodist;
/* More accurate (but more elaborate and slower) lunar
ephemeris, from Jean Meeus' *Astronomical Formulae For Calculators*,
pub. Willman-Bell. Includes all the terms given there. */
{
/* double *eclatit,*eclongit, *pie,*ra,*dec,*dist; geocent quantities,
formerly handed out but not in this version */
double pie, dist; /* horiz parallax */
double Lpr,M,Mpr,D,F,Om,T,Tsq,Tcb;
double e,lambda,B,beta,om1,om2;
double sinx, x, y, z, l, m, n;
double x_geo, y_geo, z_geo; /* geocentric position of *observer* */
jd = etcorr(jd); /* approximate correction to ephemeris time */
T = (jd - 2415020.) / 36525.; /* this based around 1900 ... */
Tsq = T * T;
Tcb = Tsq * T;
Lpr = 270.434164 + 481267.8831 * T - 0.001133 * Tsq
+ 0.0000019 * Tcb;
M = 358.475833 + 35999.0498*T - 0.000150*Tsq
- 0.0000033*Tcb;
Mpr = 296.104608 + 477198.8491*T + 0.009192*Tsq
+ 0.0000144*Tcb;
D = 350.737486 + 445267.1142*T - 0.001436 * Tsq
+ 0.0000019*Tcb;
F = 11.250889 + 483202.0251*T -0.003211 * Tsq
- 0.0000003*Tcb;
Om = 259.183275 - 1934.1420*T + 0.002078*Tsq
+ 0.0000022*Tcb;
Lpr = circulo(Lpr);
Mpr = circulo(Mpr);
M = circulo(M);
D = circulo(D);
F = circulo(F);
Om = circulo(Om);
sinx = sin((51.2 + 20.2 * T)/DEG_IN_RADIAN);
Lpr = Lpr + 0.000233 * sinx;
M = M - 0.001778 * sinx;
Mpr = Mpr + 0.000817 * sinx;
D = D + 0.002011 * sinx;
sinx = 0.003964 * sin((346.560+132.870*T -0.0091731*Tsq)/DEG_IN_RADIAN);
Lpr = Lpr + sinx;
Mpr = Mpr + sinx;
D = D + sinx;
F = F + sinx;
sinx = sin(Om/DEG_IN_RADIAN);
Lpr = Lpr + 0.001964 * sinx;
Mpr = Mpr + 0.002541 * sinx;
D = D + 0.001964 * sinx;
F = F - 0.024691 * sinx;
F = F - 0.004328 * sin((Om + 275.05 -2.30*T)/DEG_IN_RADIAN);
e = 1 - 0.002495 * T - 0.00000752 * Tsq;
M = M / DEG_IN_RADIAN; /* these will all be arguments ... */
Mpr = Mpr / DEG_IN_RADIAN;
D = D / DEG_IN_RADIAN;
F = F / DEG_IN_RADIAN;
lambda = Lpr + 6.288750 * sin(Mpr)
+ 1.274018 * sin(2*D - Mpr)
+ 0.658309 * sin(2*D)
+ 0.213616 * sin(2*Mpr)
- e * 0.185596 * sin(M)
- 0.114336 * sin(2*F)
+ 0.058793 * sin(2*D - 2*Mpr)
+ e * 0.057212 * sin(2*D - M - Mpr)
+ 0.053320 * sin(2*D + Mpr)
+ e * 0.045874 * sin(2*D - M)
+ e * 0.041024 * sin(Mpr - M)
- 0.034718 * sin(D)
- e * 0.030465 * sin(M+Mpr)
+ 0.015326 * sin(2*D - 2*F)
- 0.012528 * sin(2*F + Mpr)
- 0.010980 * sin(2*F - Mpr)
+ 0.010674 * sin(4*D - Mpr)
+ 0.010034 * sin(3*Mpr)
+ 0.008548 * sin(4*D - 2*Mpr)
- e * 0.007910 * sin(M - Mpr + 2*D)
- e * 0.006783 * sin(2*D + M)
+ 0.005162 * sin(Mpr - D);
/* And furthermore.....*/
lambda = lambda + e * 0.005000 * sin(M + D)
+ e * 0.004049 * sin(Mpr - M + 2*D)
+ 0.003996 * sin(2*Mpr + 2*D)
+ 0.003862 * sin(4*D)
+ 0.003665 * sin(2*D - 3*Mpr)
+ e * 0.002695 * sin(2*Mpr - M)
+ 0.002602 * sin(Mpr - 2*F - 2*D)
+ e * 0.002396 * sin(2*D - M - 2*Mpr)
- 0.002349 * sin(Mpr + D)
+ e * e * 0.002249 * sin(2*D - 2*M)
- e * 0.002125 * sin(2*Mpr + M)
- e * e * 0.002079 * sin(2*M)
+ e * e * 0.002059 * sin(2*D - Mpr - 2*M)
- 0.001773 * sin(Mpr + 2*D - 2*F)
- 0.001595 * sin(2*F + 2*D)
+ e * 0.001220 * sin(4*D - M - Mpr)
- 0.001110 * sin(2*Mpr + 2*F)
+ 0.000892 * sin(Mpr - 3*D)
- e * 0.000811 * sin(M + Mpr + 2*D)
+ e * 0.000761 * sin(4*D - M - 2*Mpr)
+ e * e * 0.000717 * sin(Mpr - 2*M)
+ e * e * 0.000704 * sin(Mpr - 2 * M - 2*D)
+ e * 0.000693 * sin(M - 2*Mpr + 2*D)
+ e * 0.000598 * sin(2*D - M - 2*F)
+ 0.000550 * sin(Mpr + 4*D)
+ 0.000538 * sin(4*Mpr)
+ e * 0.000521 * sin(4*D - M)
+ 0.000486 * sin(2*Mpr - D);
/* *eclongit = lambda; */
B = 5.128189 * sin(F)
+ 0.280606 * sin(Mpr + F)
+ 0.277693 * sin(Mpr - F)
+ 0.173238 * sin(2*D - F)
+ 0.055413 * sin(2*D + F - Mpr)
+ 0.046272 * sin(2*D - F - Mpr)
+ 0.032573 * sin(2*D + F)
+ 0.017198 * sin(2*Mpr + F)
+ 0.009267 * sin(2*D + Mpr - F)
+ 0.008823 * sin(2*Mpr - F)
+ e * 0.008247 * sin(2*D - M - F)
+ 0.004323 * sin(2*D - F - 2*Mpr)
+ 0.004200 * sin(2*D + F + Mpr)
+ e * 0.003372 * sin(F - M - 2*D)
+ 0.002472 * sin(2*D + F - M - Mpr)
+ e * 0.002222 * sin(2*D + F - M)
+ e * 0.002072 * sin(2*D - F - M - Mpr)
+ e * 0.001877 * sin(F - M + Mpr)
+ 0.001828 * sin(4*D - F - Mpr)
- e * 0.001803 * sin(F + M)
- 0.001750 * sin(3*F)
+ e * 0.001570 * sin(Mpr - M - F)
- 0.001487 * sin(F + D)
- e * 0.001481 * sin(F + M + Mpr)
+ e * 0.001417 * sin(F - M - Mpr)
+ e * 0.001350 * sin(F - M)
+ 0.001330 * sin(F - D)
+ 0.001106 * sin(F + 3*Mpr)
+ 0.001020 * sin(4*D - F)
+ 0.000833 * sin(F + 4*D - Mpr);
/* not only that, but */
B = B + 0.000781 * sin(Mpr - 3*F)
+ 0.000670 * sin(F + 4*D - 2*Mpr)
+ 0.000606 * sin(2*D - 3*F)
+ 0.000597 * sin(2*D + 2*Mpr - F)
+ e * 0.000492 * sin(2*D + Mpr - M - F)
+ 0.000450 * sin(2*Mpr - F - 2*D)
+ 0.000439 * sin(3*Mpr - F)
+ 0.000423 * sin(F + 2*D + 2*Mpr)
+ 0.000422 * sin(2*D - F - 3*Mpr)
- e * 0.000367 * sin(M + F + 2*D - Mpr)
- e * 0.000353 * sin(M + F + 2*D)
+ 0.000331 * sin(F + 4*D)
+ e * 0.000317 * sin(2*D + F - M + Mpr)
+ e * e * 0.000306 * sin(2*D - 2*M - F)
- 0.000283 * sin(Mpr + 3*F);
om1 = 0.0004664 * cos(Om/DEG_IN_RADIAN);
om2 = 0.0000754 * cos((Om + 275.05 - 2.30*T)/DEG_IN_RADIAN);
beta = B * (1. - om1 - om2);
/* *eclatit = beta; */
pie = 0.950724
+ 0.051818 * cos(Mpr)
+ 0.009531 * cos(2*D - Mpr)
+ 0.007843 * cos(2*D)
+ 0.002824 * cos(2*Mpr)
+ 0.000857 * cos(2*D + Mpr)
+ e * 0.000533 * cos(2*D - M)
+ e * 0.000401 * cos(2*D - M - Mpr)
+ e * 0.000320 * cos(Mpr - M)
- 0.000271 * cos(D)
- e * 0.000264 * cos(M + Mpr)
- 0.000198 * cos(2*F - Mpr)
+ 0.000173 * cos(3*Mpr)
+ 0.000167 * cos(4*D - Mpr)
- e * 0.000111 * cos(M)
+ 0.000103 * cos(4*D - 2*Mpr)
- 0.000084 * cos(2*Mpr - 2*D)
- e * 0.000083 * cos(2*D + M)
+ 0.000079 * cos(2*D + 2*Mpr)
+ 0.000072 * cos(4*D)
+ e * 0.000064 * cos(2*D - M + Mpr)
- e * 0.000063 * cos(2*D + M - Mpr)
+ e * 0.000041 * cos(M + D)
+ e * 0.000035 * cos(2*Mpr - M)
- 0.000033 * cos(3*Mpr - 2*D)
- 0.000030 * cos(Mpr + D)
- 0.000029 * cos(2*F - 2*D)
- e * 0.000029 * cos(2*Mpr + M)
+ e * e * 0.000026 * cos(2*D - 2*M)
- 0.000023 * cos(2*F - 2*D + Mpr)
+ e * 0.000019 * cos(4*D - M - Mpr);
beta = beta/DEG_IN_RADIAN;
lambda = lambda/DEG_IN_RADIAN;
l = cos(lambda) * cos(beta);
m = sin(lambda) * cos(beta);
n = sin(beta);
eclrot(jd,&l,&m,&n);
dist = 1/sin((pie)/DEG_IN_RADIAN);
x = l * dist;
y = m * dist;
z = n * dist;
/* *ra = atan_circ(l,m) * DEG_IN_RADIAN;
*dec = asin(n) * DEG_IN_RADIAN; */
geocent(lst,geolat,elevsea,&x_geo,&y_geo,&z_geo);
x = x - x_geo; /* topocentric correction using elliptical earth fig. */
y = y - y_geo;
z = z - z_geo;
*topodist = sqrt(x*x + y*y + z*z);
l = x / (*topodist);
m = y / (*topodist);
n = z / (*topodist);
*topora = atan_circ(l,m) * HRS_IN_RADIAN;
*topodec = asin(n) * DEG_IN_RADIAN;
}
lpsun(jd,ra,dec)
double jd, *ra, *dec;
/* Low precision formulae for the sun, from Almanac p. C24 (1990) */
/* ra and dec are returned as decimal hours and decimal degrees. */
{
double n, L, g, lambda,epsilon,alpha,delta,x,y,z;
n = jd - 2451545.0;
L = 280.460 + 0.9856474 * n;
g = (357.528 + 0.9856003 * n)/DEG_IN_RADIAN;
lambda = (L + 1.915 * sin(g) + 0.020 * sin(2. * g))/DEG_IN_RADIAN;
epsilon = (23.439 - 0.0000004 * n)/DEG_IN_RADIAN;
x = cos(lambda);
y = cos(epsilon) * sin(lambda);
z = sin(epsilon)*sin(lambda);
*ra = (atan_circ(x,y))*HRS_IN_RADIAN;
*dec = (asin(z))*DEG_IN_RADIAN;
}
double jd_moon_alt(alt,jdguess,lat,longit)
double alt, jdguess, lat, longit;
{
/* returns jd at which moon is at a given
altitude, given jdguess as a starting point. */
double jdout;
double deriv, err, del = 0.002;
double ra,dec,dist,sid,ha,alt2,alt3;
short i = 0;
/* first guess */
sid=lst(jdguess,longit);
accumoon(jdguess,lat,sid,0.,&ra,&dec,&dist);
ha = lst(jdguess,longit) - ra;
alt2 = altit(dec,ha,lat);
jdguess = jdguess + del;
sid = lst(jdguess,longit);
accumoon(jdguess,lat,sid,0.,&ra,&dec,&dist);
alt3 = altit(dec,(sid - ra),lat);
err = alt3 - alt;
deriv = (alt3 - alt2) / del;
while((fabs(err) > 0.01) && (i < 10)) {
jdguess = jdguess - err/deriv;
sid=lst(jdguess,longit);
accumoon(jdguess,lat,sid,0.,&ra,&dec,&dist);
alt3 = altit(dec,(sid - ra),lat);
err = alt3 - alt;
i++;
if(i == 9) return (-1.0e10); /* bad status flag */
}
jdout = jdguess;
return(jdout);
}