-
Notifications
You must be signed in to change notification settings - Fork 0
/
eclipse.html
executable file
·3059 lines (2704 loc) · 91.9 KB
/
eclipse.html
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
<!DOCTYPE html>
<html manifest='eclipse.manifest'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<script type='text/javascript' src="jq/jquery.js"></script>
<script type='text/javascript' src="debug.js"></script>
<script src='worldmap/d3.v3.js'></script>
<script src='worldmap/topojson.v0.min.js'></script>
<script src="worldmap/world-110m.js"></script>
<script type="text/javascript">
/**
Eclipse calculation script from Jean Meeus Formulas
Between years 1000 and 3000 AD
*/
if (typeof(p_r) == "undefined") {
var g_d = false;
function p_r() {} // debug.js not available: NO debugging
}
const g_version = "20210611";
// 20200503 Added GPS support
var debug = false;
// all done
var g_done = false;
var ___elem = document.createElement('canvas');
var g_canvas = ___elem.getContext('2d') ? true : false;
// Curve and text colors solar eclipses
const COLOR_HORIZONCURVES = "#00AA00";
const COLOR_HORIZONMAXCURVES = "red";
const COLOR_PENUMBRALIMIT = "red";
const COLOR_TEXT1 = "red";
const COLOR_TEXT2 = "red";
const COLOR_MAXMAGNITUDES = "white";
const FONTSIZE = 10;
const LETTERFONT = "Arial";
// World map colors
const COLOR_OCEAN = '#88C0FF';
const COLOR_LAND = '#d7c7ad';
const COLOR_COASTLINE = '#766951';
const CHECKLOCAL = 2
const UNDEFINED = "undefined"
const FLATT = 0.99665;
const RHO_1 = 0.9972;
const PENUMBRAL = 1
const PARTIAL_SOLAR = 2
const ANNULAR_SOLAR = 3
const TOTAL_SOLAR = 4
const DAYS_CENT = 36525;
// extraflags bits
const P_HYBRID = 1;
const P_NONCENTRAL = 2;
const P_ANNULAR = 4; // otherwise total
///
const OUT_OF_RANGE = 9999999;
var edata;
var g_eclipsedata;
var eclnumber;
const RAD = 180./Math.PI;
// ploteclipse
const D_MAGN=60;
const CURVECOUNT = 5; // should be a divisor of D_MAGN
const D_MAGN2 =(D_MAGN*2+2);
const MAXPOSITIONS =(D_MAGN2*6+45);
const NOT_FILLED_IN = 9999;
const MINYEAR = 1000;
const MAXYEAR = 3000;
const PLOT_LINE=1;
const PLOT_CIRCLE=3;
const PLOT_TEXT=4;
const VISIBLEHERE = 2; // return value if at least the umbral phase or middle of the eclipse is visible here
</script>
<style type="text/css">
* {
font-family: Century Gothic, Arial, Helvetica, Comic Sans MS, Verdana;
}
a {
text-decoration: none;
color: red;
font-weight: bold;
}
a img {
border-width: 0px;
}
a:hover {
text-decoration: underline;
}
input[type="button"] {
border: solid 1px black;
margin: 2px;
padding: 2px;
width: 6em;
}
table.result, table#form {
border: solid black 1px;
padding: 5px;
}
table.result_solar {
background: #FCC;
min-width: 200px;
}
table.result_solar_here {
background: #CFC;
min-width: 200px;
}
table.result_lunar {
background: #FFA;
min-width: 200px;
}
table#main td {
text-align: center;
}
pre#debug {
border: solid black 1px;
background-color: #FC1;
font-family: Lucida Console;
font-size: 8pt;
max-height: 400px;
overflow: scroll;
width: 100%;
}
div#form {
float: left;
}
</style>
<script type="text/javascript">
//var g_d = null;
//***** General functions ***********************************
function hmstring(t, accuracy, type)
{
var prefix = '';
var allseconds = Math.abs(t * 3600);
if (accuracy == 1)
allseconds += 30;
else if (accuracy == 2)
allseconds += 3;
else if (accuracy == 3)
allseconds += 0.5;
var seconds = allseconds % 60;
var minutes = Math.floor(((allseconds - seconds) / 60) % 60);
var hours = Math.floor(allseconds / 3600)
hmstr = hours + ":" + pad(minutes, 2, "0");
if (accuracy == 2)
hmstr += '.' + Math.floor(seconds / 6);
else if (accuracy == 3)
hmstr += ":" + pad("" + Math.floor(seconds), 2, "0");
if (arguments.length == 2)
return (t < 0 ? '-' : '') + hmstr;
else if (type == 1)
return hmstr + (t < 0 ? ' S' : ' N');
else if (type == 2)
return hmstr + (t < 0 ? ' W' : ' E');
}
/*
* Return parameter value of name (case sensitive !)
*/
function get_value(parametername)
{
readvalue = (location.search ? location.search.substring(1) : false);
if (readvalue)
{
parameter = readvalue.split('&');
for (i = 0; i < parameter.length; i++)
{
if (parameter[i].split('=')[0] == parametername)
return parameter[i].split('=')[1];
}
}
return false;
}
function showhide(id, on)
{
var disp_id = document.getElementById(id);
if (arguments.length < 2 || on == -1) on = (disp_id.style.display != 'block');
if (on)
disp_id.style.display = 'block';
else
disp_id.style.display = 'none';
// var textid = document.getElementById("text_" + id);
return disp_id.style.display;
}
//document.write("<input type=text onchange=\"alert(zhmstring(this.value,1)+ ',' + zhmstring(this.value,2)+ ','+zhmstring(this.value,3));\">");
function getaltazimuth(theta, lat, alfa, delta) {
var alt = sphsin(lat, delta, alfa - theta);
var azymuth = range(sphcos(alt, lat, delta, range(alfa - theta) >= 180 ? -1 : 1));
return new Array(alt, azymuth);
}
function dsin(x) {
if (x == 0) return 0; // Dolphin sometimes returns 0.467...
return Math.sin((Math.PI / 180) * x)
}
function dcos(x) {
if (x == 0) return 1; // Dolphin sometimes returns 0.88...
return Math.cos((Math.PI / 180) * x)
}
function dtan(x) {
if (x == 0) return 0; // Dolphin sometimes returns 0.467...
return Math.tan((Math.PI / 180) * x)
}
function dasin(x) {
return (180 / Math.PI) * Math.asin(x)
}
function dacos(x) {
return (180 / Math.PI) * Math.acos(x)
}
function datan(x) {
return (180 / Math.PI) * Math.atan(x)
}
function datan2(y, x) {
var a;
if ((x == 0) && (y == 0)) {
return 0;
}
else {
a = datan(y / x);
if (x < 0) {
a = a + 180;
}
if (y < 0 && x > 0) {
a = a + 360;
}
return a;
}
}
function ipart(x) {
var a;
if (x > 0) {
a = Math.floor(x);
}
else {
a = Math.ceil(x);
}
return a;
}
function sphsin(a, b, gamma) {
return dasin(dsin(a) * dsin(b) + dcos(a) * dcos(b) * dcos(gamma));
}
function sphcos(alpha, beta, c, sgn) {
return sgn * dacos(dsin(c) / (dcos(alpha) * dcos(beta)) - dtan(alpha) * dtan(beta));
}
function range(x, therange, offset)
{
var a, b;
if (arguments.length < 2) therange = 360;
if (arguments.length < 3) offset = 0;
b = x / therange;
a = therange * (b - ipart(b));
if (a < 0) {
a = a + therange;
}
return a
}
//
// round rounds the number num to dp decimal places
// the second line is some C like jiggery pokery I
// found in an O'Reilly book which means if dp is null
// you get 2 decimal places.
//
function round(num, dp)
{
if (dp == 0) return Math.round(num);
num = Math.round(num * Math.pow(10, dp)) / Math.pow(10, dp);
var x = Math.abs(num);
var s = num < 0 ? '-' : '';
s += (Math.floor(x) + '.');
x = Math.floor(Math.pow(10, dp) * (x - Math.floor(x)) + 0.5);
s += pad(x.toString(), dp, '0');
return s;
// return Math.round (num * Math.pow(10, dp)) / Math.pow(10, dp);
}
//alert(round(123.34567788,4) + ' ' + round(-123.34567788,4) + ' ' + round(0,4) + ' ' + round(123,4) + ' ' + round(123.34567788,1) + ' ' + round(-0.0034567788,4));
// parsefield converts deg:min:sec or hr:min:sec to a number
function parsefield(field) {
var str = field.value;
var res = 0;
if (str != undefined)
cleanupfield(field);
else
str = field;
if (str.indexOf('.') >= 0) {
res = str * 1;
if (!isNaN(res)) return res;
else return 0;
}
var col1 = str.indexOf(":");
// if (col1 < 0) col1=str.indexOf("*");
var col2 = str.lastIndexOf(":");
// if (col2 < 0) col2=str.lastIndexOf("*");
if (col1 < 0) return parseInt(str);
if (str.substring(0, 1) == "-") {
res = parseInt(str.substring(1, col1), 10);
} else {
res = parseInt(str.substring(0, col1), 10);
}
if (col2 > col1) {
res += (parseInt(str.substring(col1 + 1, col2), 10) / 60.0) +
(parseInt(str.substring(col2 + 1, str.length), 10) / 3600.0);
} else {
res += (parseInt(str.substring(col1 + 1, str.length), 10) / 60.0);
}
if (str.substring(0, 1) == "-") {
return -res;
} else {
return res;
}
}
function cleanupfield(field)
{
var str = field.value;
// - key not accessible in phone
str = str.replace(/^[\*#]/g, "-");
str = str.replace(/[\*#]/g, ":");
field.value = str;
}
/* PAD -- Pad a string to a given length with a given fill character. */
function pad(str, howlong, padwith) {
var s = str.toString();
while (s.length < howlong) {
s = padwith + s;
}
return s;
}
/*
Netfront 3.0 has a bug in which String.fromCharCode(x) returns an empty string
instead of the character with the code x.
This workaround, use this instead on unescape().
*/
function unescape_u(x)
{
if (navigator.appName != 'ACCESS NetFront' || navigator.appVersion != '3.0')
return unescape(x);
x = x.replace(/%u([0-9A-F][0-9A-F])[0-9A-F][0-9A-F]/g, "%$1");
var z = "",
y, ind;
y = x;
while ((ind = y.indexOf('%')) >= 0)
{
z += y.substr(0, ind) + eval("\"\\u" + y.substr(ind + 1, 2) + "00\"");
y = y.substr(ind + 3);
}
z += y;
return z;
}
function clearCookie()
{
var expDays = -1;
var exp = new Date();
exp.setTime(exp.getTime() - 86400000);
document.cookie = "; expires=" + exp.toGMTString();
}
Math.sign = function(x)
{
return x < 0 ? -1 : 1;
} ;
/*******************************************************************************
*
* calculates a certain lunar phase
* Astronomical Formulae for Calculators (1979), 1st ed, ISBN 0-943396-22-0
*
******************************************************************************/
function sumsin(e,coeff, angle)
{
var h = 1.0; //force float
return h*e*coeff*dsin(angle);
}
function sumcos(e,coeff, angle)
{
var h = 1.0; //force float
return h*e*coeff*dcos(angle);
}
function new_full_moon(e,T, M,M_,F) /* new and full moon */
{
var sum = (1734.-3.93*T)*dsin(M);
sum += sumsin(1, 21,M+M);
sum += sumsin(1,-4068,M_);
sum += sumsin(1, 161,M_+M_);
sum += sumsin(1, -4,M_+M_+M_);
sum += sumsin(1, 104,F);
sum += sumsin(e, -51,M+M_);
sum += sumsin(e, -74,M-M_);
sum += sumsin(e, 4,F+M);
sum += sumsin(e, -4,F-M);
sum += sumsin(1, -6,F+M_);
sum += sumsin(1, 10,F-M_);
sum += sumsin(e, 5,M+M_*M_);
return (sum/10000.);
}
function first_last_quarter(e,T, fq, M,M_,F)
{
var h;
var sum = (1721.-4.*T) * dsin(M);
sum += sumsin(1, 21,2*M);
sum += sumsin(1,-6280,M_);
sum += sumsin(1, 89,2*M_);
sum += sumsin(1, -4,3*M_);
sum += sumsin(1, 79,F);
sum += sumsin(e, -119,M+M_);
sum += sumsin(e, -47,M-M_);
sum += sumsin(e, 3,F+M);
sum += sumsin(e, -4,F-M);
sum += sumsin(1, -6,F+M_);
sum += sumsin(1, 21,F-M_);
sum += sumsin(e, 3,M+2*M_);
sum += sumsin(e, 4,M-2*M_);
sum += sumsin(e*e, -3,2*M+M_);
h=28. -4.0 * dcos(M) + 3.0 * dcos(M_);
if (!fq) h = -h;
return (sum+h)/10000.;
}
function angler(x0,x1,x2,x3,t)
{
return range(x0+t* (x1 + t* (x2 + t*x3)));
}
/*
* calculate each phase
* k % 4 == 0 NM 1 FQ 2 FM 3 LQ
*/
function phase(k)
{
var fq;
var cor,h,kk,d;
var t;
var M,M_,F;
var t1 = (k/4.)/1236.853;
var i = (k+50000);
var j = (i % 4);
kk = (i-50000)/4;
jd = (0.75933+(29.53058868+77e-12*kk -81.9e-18*kk*kk)*kk);
cor = 0.00033 * dsin(range(166.56+132.87*t1,-0.0091731*t1*t1));
jd = jd + cor;
M = angler(359.2242, 29.10535608,-21.77e-12,-1834e-18,kk);
M_ = angler(306.0253,385.81691806, 7014e-12 , 6.53e-15,kk);
F = angler(21.2964,390.67050646,-1080e-12 ,-1263e-18,kk);
F += F; /* always calculate with 2*F !! */
e = 1.-t1*(0.0024954+(7522e-9)*t1);
if (j & 1)
jd += first_last_quarter(e,t1,k == 1, M,M_,F);
else
jd += new_full_moon(e,t1, M,M_,F);
return new Array(jd, M, M_, F/2);
}
/* jdtodatetime -- Convert Julian date to year, month, day, hour, minute, second which are
returned as an Array. */
function jdtodatetime(td, offset)
{
var z, f, a, alpha, b, c, d, e, mm;
var tdfrac, ij;
if (arguments.length == 1) {
offset = 0;
} else if (offset == 1900) {
offset = 2415020.5;
} else if (offset == 2000) {
offset = 2451545.5;
} else {
offset = 0;
}
td += offset;
tdfrac = td-Math.floor(td);
td = Math.floor(td) + 0.5;
z = Math.floor(td);
f = td - z;
if (z < 2299161.0) {
a = z;
} else {
alpha = Math.floor((z - 1867216.25) / 36524.25);
a = z + 1 + alpha - Math.floor(alpha / 4);
}
b = a + 1524;
c = Math.floor((b - 122.1) / 365.25);
d = Math.floor(365.25 * c);
e = Math.floor((b - d) / 30.6001);
mm = Math.floor((e < 14) ? (e - 1) : (e - 13));
ij = tdfrac * 86400.0;
// return y-m-d-h-m-s
return new Array(
Math.floor((mm > 2) ? (c - 4716) : (c - 4715)),
mm,
Math.floor(b - d - Math.floor(30.6001 * e) + f),
Math.floor(ij / 3600),
Math.floor((ij / 60) % 60),
Math.floor(ij % 60)
);
}
// timeonly==1: time; timeonly==-1: date only
function edate(j, offset, timeonly)
{
var Months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
);
var date;
if (arguments.length == 1)
offset = 0;
j += (30.0 / (24 * 60 * 60)); // Round to nearest minute
var latlon = getlatlon();
if (latlon.utcdiff) {
j += latlon.utcdiff/24; // UTC difference
}
date = jdtodatetime(j, offset);
if (typeof(timeonly) == UNDEFINED) timeonly = 0;
var ret = "";
if (timeonly == 1)
ret = pad(date[3], 2, " ") + ":" + pad(date[4], 2, "0");
else {
ret = date[0] + " " + Months[date[1] - 1] + " " + pad(date[2], 2, " ");
if (timeonly == 0) ret += (" " + pad(date[3], 2, " ") + ":" + pad(date[4], 2, "0"));
}
return ret;
}
function eclipse_number(month, year)
{
var z,i;
var error = "";
// year = year.parseInt();
if (year < 50) {
year += 2000;
} else if (year < 100) {
year += 1900;
}
if (month < 1 || month > 12) {
error += "months only from 1 to 12\n";
}
if (year < 0 || year > 4000) {
error += "years only within 2nd or 3rd millennium\n";
}
if (error != "") {
alert(error);
return OUT_OF_RANGE;
}
z = 2.10745*((year-1900) + month/12.) + 0.6;
i = Math.floor((z + 10000.) - 10000);
if (Math.abs(i) > 4200) return (OUT_OF_RANGE);
return i;
}
function Eclipsedata(number,jd, M,M_,F,e,gamma,l1)
{
this.number = number
this.jd = jd
this.M = M
this.M_ = M_
this.F = F
this.e = e
this.gamma = gamma
this.l1 = l1
this.tle = new Array(); // times in human readable format (both)
this.tse = new Array(); // extra eclipse data (solar only)
this.xle = new Array(); // coordinates of center of moon relative to center of Sun or Earth shadow in degrees
this.yle = new Array();
this.lunar = false;
this.debug = false;
this.pos_angle = new Array();
this.alt_sun = new Array();
this.visible_here = false;
}
function eclipse_maindata(ecl_number, first, lunar)
{
var a,k,h,hh,dt,s,c;
var ish, n;
var two_eclipses = false;
/* ----------------------------------------------calculate lunation number */
a = 5.86883*ecl_number-0.69+50000.;
/* ------------------------------------------------------time out of range */
if (Math.abs(a-50000.) > 20000.) return(OUT_OF_RANGE);
if (lunar) a=a+0.5;
k = Math.floor(a + 0.5);
h = k-a;
ish = h < 0 ? -1 : 1;
hh = Math.abs(h) - 0.34;
/* ---------------------two eclipses possible with one lunation interval ? */
/*
if (hh > 0)
{
if (!first) k = k-ish;
two_eclipses = true;
}
*/
if (!first) k = k-ish;
if (lunar) k = k-0.5;
//p_r(a + " " + k);
k -= 50000;
var T = k/1236.853;
var e = 1.-T*(0.0024954+(7522e-9)*T);
var a = phase(Math.round(k*4));
var jd = a[0];
p_r([first,jd]);
var m = a[1];
var m1 = a[2];
var f = a[3];
s = 51959.5;
c = 0.;
omega = angler(259.18e0,-1934.182008e0,2078.e-6,22.e-7,T);
s += sumcos(e, -48.,m);
s += sumcos(e*e, 20.,2*m);
s += sumcos(1,-3283.,m1);
s += sumcos(e, -60.,m+m1);
s += sumcos(e, 41.,m-m1);
c += sumsin(e, 2065.,m);
c += sumsin(e *e, 24.,2*m);
c += sumsin(1, -390.,m1);
c += sumsin(1, 115.,2*m1);
c += sumsin(e, -73.,m+m1);
c += sumsin(e, -67.,m-m1);
c += sumsin(1, 117.,2*f);
let gamma = s*dsin(f)+c*dcos(f)-(dcos(f) < 0 ? -1 : 1)*25.*dsin(omega);
gamma = gamma/1e4;
l2 = -59.;
l2 += sumcos(e,-46.,m);
l2 += sumcos(1,182.,m1);
l2 += sumcos(1, -4.,2*m1);
l2 += sumcos(e, 5.,m+m1);
l2 = l2/1e4;
l1 = 0.5460-l2;
let speed = 13.1+0.96*dcos(m1);
dt = ((dcos(f) < 0 ? -1 : 1)*980.5*gamma)/(1e4*speed);
jd = jd - dt;
T = jd / 36525;
// check if an eclipse is available (shadow touches eclipsed object)
if (Math.abs(gamma)-l1 < RHO_1) {
ecldata = new Eclipsedata(ecl_number,jd,m,m1,f,e,gamma,l1);
eclnumber = ecl_number;
ecldata.lunar = lunar;
ecldata.speed = speed;
ecldata.maximum_local_magn = false;
return ecldata;
}
return false;
}
function eclipse_auxdata(edata) // auxiliary eclipse data
{
for (var i = 0; i < 7; i++) edata.tle[i] = "";
var l2 = 0.546 - edata.l1; // umbral limit
edata.l2 = l2; // penumbral limit
var d_mu = Math.PI * 2;
edata.extra = "";
var l = range(279.691 + (.9856473354 + 227e-15 * edata.jd) * edata.jd);
var m2 = l + 78.8 - (edata.jd * 47e-6);
var corr = (0.04 * dcos(m2) * e + 1.92) * e * dsin(m2);
var ll = l + corr;
var epsilon = 23.4523 - (edata.jd / 28e5);
var delta = dasin(dsin(ll) * dsin(epsilon));
edata.delta = delta;
var d1 = dasin(dsin(delta) / RHO_1);
var alfa = datan2(dsin(ll) * dcos(epsilon), dcos(ll));
edata.alfa = alfa;
var h = dasin(dsin(epsilon) * dcos(alfa));
var h2 = 5.6 * sign(dcos(edata.F));
if (edata.lunar) h = -h;
var psi = -h - h2;
// no negative numbers
var jd = edata.jd + 100000000;
var frac = jd - Math.floor(jd);
var mu = alfa - l - (360. * frac);
var u = range(mu + 180);
edata.mu = u - 180;
edata.psi = psi;
// ----------------------------------------------------------lunar eclipse
if (edata.lunar) {
edata.magn = (1.0129 + l2 - Math.abs(edata.gamma)) / 0.545;
// ---------------------------------------check if it is an umbral eclipse
if (edata.magn < 0.) {
edata.flags = PENUMBRAL;
edata.magn = (1.5572 - l2 - Math.abs(edata.gamma)) / 0.545;
p_r([edata.magn, l2, edata.gamma]);
}
var pp = 1.5572 - l2;
lunar_contact_times(edata, edata.gamma, 3, 3, "middle of the eclipse");
// penumbral lunar eclipse
if (edata.flags == PENUMBRAL) {
edata.title = "Penumbral";
lunar_contact_times(edata, pp, 2, 4, "penumbral");
} else {
var up = 1.0129 + l2;
// total lunar eclipse
if (edata.magn > 1) {
var tp = 0.4679 + l2;
edata.title = "Total";
lunar_contact_times(edata, tp, 2, 4, "totality");
lunar_contact_times(edata, up, 1, 5, "umbral");
lunar_contact_times(edata, pp, 0, 6, "penumbral");
}
// partial lunar eclipse
else {
edata.title = "Partial";
lunar_contact_times(edata, up, 2, 4, "umbral");
lunar_contact_times(edata, pp, 1, 5, "penumbral");
}
}
edata.extra = "<div class=\"solarresult\">Max magn = " + round(edata.magn, 2) + "</div>";
for (i = 0; i < 7; i++) {
if (edata.tle[i] != "") {
edata.extra += "<br/>" + edata.tle[i];
}
}
} else {
// ----------------------------------------------------------solar eclipse
edata.magn = (1.5432 - l2 - Math.abs(edata.gamma)) / (0.546 - 2 * l2);
edata.tan_f2 = 0.004664 + 0.000078 * dcos(edata.M);
var gam1 = edata.gamma / RHO_1;
edata.flags = PARTIAL_SOLAR;
edata.extraflags = 0;
// axis of lunar shadow touches Earth: central eclipse
if (Math.abs(gam1) < 1.) {
if (l2 <= 0) {
var w = Math.sqrt(1. - gam1 * gam1) * edata.tan_f2;
edata.flags = ANNULAR_SOLAR;
if ((l2 + w) > 0) {
edata.flags = TOTAL_SOLAR;
edata.extraflags |= P_HYBRID;
}
} else
edata.flags = TOTAL_SOLAR;
// part of umbra touching the Earth but not the axis
} else if ((Math.abs(edata.gamma) - Math.abs(l2)) < RHO_1) {
if (l2 <= 0)
edata.extraflags |= P_ANNULAR;
edata.extraflags |= P_NONCENTRAL;
}
p_r([edata.gamma, l2, (Math.abs(edata.gamma) - Math.abs(l2)), RHO_1, (Math.abs(edata.gamma) - Math.abs(l2)) < RHO_1, edata.flags, edata.extraflags, edata.visible_here]);
if (edata.extraflags & P_HYBRID)
edata.title = "Hybrid";
else if (edata.flags == ANNULAR_SOLAR)
edata.title = "Annular";
else if (edata.flags == TOTAL_SOLAR)
edata.title = "Total";
else if (edata.extraflags & P_NONCENTRAL) {
if (edata.extraflags & P_ANNULAR)
edata.title = "Annular noncental";
else
edata.title = "Total noncental";
} else
edata.title = "Partial";
edata.extra = "<div class=\"solarresult\">";
if (edata.flags == PARTIAL_SOLAR)
edata.extra += "Max magn=" + round(edata.magn, 2);
}
var diff = deltat(edata.jd);
edata.T = edata.jd / 36525;
// correct for UT-ET
edata.jd -= diff;
var sd = dsin(d1);
var cd = dcos(d1);
edata.d1 = d1;
edata.sd = sd;
edata.cd = cd;
// location of greatest partial eclipse
if (!edata.lunar) {
var phi, lambda;
edata.worldmapdata = false; // reset worldmap data
edata.d_mu = d_mu;
if (edata.flags == PARTIAL_SOLAR) {
phi = dasin(dcos(d1) * dcos(psi));
if (edata.gamma < 0) phi = -phi;
var ha = dacos(-dtan(phi) * dtan(d1));
s = sign(edata.gamma) * sign(psi);
lambda = range(edata.mu + s * ha + diff * 360);
/* greatest phase at partial eclipses */
var xy = calc_greatest_phase(edata);
if (g_canvas)
edata.worldmapdata = calcworldmap(xy.latitude, xy.longitude);
} else {
var a = axpos(0, edata, d1, diff, l2); // calculate position of middle eclipse
var axisdata0 = a;
// world map centered around position of middle eclipse
if (g_canvas)
edata.worldmapdata = calcworldmap(axisdata0.latitude, axisdata0.longitude);
// More info....about central eclipse
edata.plotdata = [];
var max = 120; // 2 hours
var step = 2; //!! 1 ???
p_r(edata.gamma);
if (Math.abs(edata.gamma) > 0.9) {
step = 1;
}
var n = 0;
//xxxx
var begin = axpos(-1, edata, d1, diff, l2);
var end = axpos(1, edata, d1, diff, l2);
edata.plotdata[n++] = begin;
for (i = -max; i <= max; i += step) {
var axisdata = axpos(i / 1440, edata, d1, diff, l2);
if (axisdata.x) {
edata.plotdata[n] = axisdata;
n++;
}
}
edata.plotdata[n] = end;
edata.extra += ("<br /> Max duration " + hmstring(axisdata0.duration, 1) + " min");
edata.extra += ("<br />" + hmstring(axisdata0.latitude, 0, 1) + ' ' + hmstring(range(axisdata0.longitude + 180) - 180, 0, 2));
}
if (g_canvas) {
var npoints = Math.floor(get_value('p'));
if (npoints > D_MAGN * 2) npoints = D_MAGN * 2;
else if (npoints < 2) npoints = D_MAGN;
var positions = calc_sunrise_sunset_curves(edata, 1, npoints);
}
edata.positions = positions;
}
edata.extra += "</div>";
return edata;
}
function calc_sunrise_sunset_curves(edata, dist, d_magn)
{
var i, j, jj, count1, poscount = 0; //!!
var r, r_2, l1_2, alpha, k, m, dt, lambda_middle;
var d_magn2 = d_magn * 2 + 2;
var count2 = 0;
var positions = [];
var lastlocation = MAXPOSITIONS;
edata.d_magn2 = d_magn2;
l1_2 = edata.l1 * edata.l1;
count1 = poscount;
edata.timediff_limit = [];
//p_r("poscount="+poscount+ ", d_magn="+d_magn);
for (i = -d_magn; i <= d_magn; i += 1, count1++) {
positions[i] = [];
k = Math.abs(i) / d_magn;
k = k * (edata.l1 - edata.l2) * dist;
k = k + edata.l2;
k = k * Math.sign(i);
k = edata.gamma + k;
/* r = (edata.gamma + Math.sign(i)*(l2 + (abs(i)/(real)d_magn))*(l1-l2)); */
//p_r(i + " " + k);
if (k >= 1. || k <= -1.) {
//p_r("i="+i);
continue;
}
r = edata.gamma - k;
r_2 = r * r;
//p_r("k="+k+" i="+i + " count1="+count1 + " r="+r);
alpha = dacos(k);
dt = dsin(alpha) / edata.speed;
if (Math.abs(i) == d_magn) {
m = 0.; /* eliminate rounding errors */
edata.timediff_limit[(i / d_magn + 1) / 2] = dt;
} else if (r_2 > l1_2) {
m = 0.;
} else {
m = Math.sqrt(l1_2 - r_2) / edata.speed;
}
//p_r([i,m,dt*1440+"min",k,alpha]);
count2 = 0;
for (j = -1; j <= 1; j += 2) {
var coord = calc_lat_lon(edata, alpha, j, dt * j);
positions[i][j] = [];
lambda_middle = coord.lambda;
//p_r([coord, d_magn2, lambda_middle]);
jj = 0;
for (jj = -1; jj <= 1; jj++, count2 += d_magn2) {
if (Math.abs(i) == d_magn && !jj) {}
coord.lambda = (lambda_middle + (m * jj) * 360.);
positions[i][j][jj] = {
latitude: coord.phi,
longitude: coord.lambda
};
//if (jj==0 && i==0) p_r([i,j,jj,positions[i][j][jj]]);
}
}
}
return positions;
}
/* for eclipses in which the moon shadow does not cross the Earth entirely */
function plot_sunrise_sunset_curves(edata)
{
var i, j;
var keys = Object.keys(edata.positions);
//p_r(keys);
edata.corner_points = []; // corner points of sunrise / sunset loop needed for penumbra limit
keys.sort(function(a, b) {
return a - b
});
var positions = [];
for (i in keys) {
positions[i] = edata.positions[keys[i]];
//p_r(i);
}
var lastindex = edata.d_magn2 - 2;
var ctx;
edata.magnitudecurvepoints = {};
ctx = edata.worldmapdata.context;
var diameter = edata.worldmapdata.radius * 2;
// Reverse the arrays
var plotpoints = [];
var curve_count = D_MAGN / CURVECOUNT; // should be an int !
for (i in positions) { // i are points ranging from south to north
for (j in positions[i]) { // j are points in left or right loop
for (jj = -1; jj <= 1; jj++) { // jj are points of end, max and begin @ sunrise / sunset
var xy = calc_x_y(edata.worldmapdata, positions[i][j][jj]["latitude"], positions[i][j][jj]["longitude"]);
if (!plotpoints[jj]) plotpoints[jj] = [];
if (!plotpoints[jj][j]) plotpoints[jj][j] = [];
//??
// begin end curves of given magnitude in steps of 1/curve_count
if (i % curve_count == 0 && jj == -1) {
if (!edata.magnitudecurvepoints[j]) edata.magnitudecurvepoints[j] = [];
//if (!edata.magnitudecurvepoints[jj][j]) edata.magnitudecurvepoints[jj][j] = [];
edata.magnitudecurvepoints[j][i/curve_count] = xy;
p_r("i="+(i/curve_count)+",j="+j+",jj="+jj+",xy="+xy.latitude+","+xy.longitude);