@metagl/sdk-render 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3175 @@
1
+ /*!
2
+ * satellite-js v2.0.2
3
+ * (c) 2013 Shashwat Kandadai and UCSC
4
+ * https://github.com/shashwatak/satellite-js
5
+ * License: MIT
6
+ */
7
+
8
+ var pi = Math.PI;
9
+ var twoPi = pi * 2;
10
+ var deg2rad = pi / 180.0;
11
+ var rad2deg = 180 / pi;
12
+ var minutesPerDay = 1440.0;
13
+ var mu = 398600.5; // in km3 / s2
14
+ var earthRadius = 6378.137; // in km
15
+ var xke = 60.0 / Math.sqrt(earthRadius * earthRadius * earthRadius / mu);
16
+ var tumin = 1.0 / xke;
17
+ var j2 = 0.00108262998905;
18
+ var j3 = -0.00000253215306;
19
+ var j4 = -0.00000161098761;
20
+ var j3oj2 = j3 / j2;
21
+ var x2o3 = 2.0 / 3.0;
22
+
23
+ var constants = Object.freeze({
24
+ pi: pi,
25
+ twoPi: twoPi,
26
+ deg2rad: deg2rad,
27
+ rad2deg: rad2deg,
28
+ minutesPerDay: minutesPerDay,
29
+ mu: mu,
30
+ earthRadius: earthRadius,
31
+ xke: xke,
32
+ tumin: tumin,
33
+ j2: j2,
34
+ j3: j3,
35
+ j4: j4,
36
+ j3oj2: j3oj2,
37
+ x2o3: x2o3
38
+ });
39
+
40
+ /* -----------------------------------------------------------------------------
41
+ *
42
+ * procedure days2mdhms
43
+ *
44
+ * this procedure converts the day of the year, days, to the equivalent month
45
+ * day, hour, minute and second.
46
+ *
47
+ * algorithm : set up array for the number of days per month
48
+ * find leap year - use 1900 because 2000 is a leap year
49
+ * loop through a temp value while the value is < the days
50
+ * perform int conversions to the correct day and month
51
+ * convert remainder into h m s using type conversions
52
+ *
53
+ * author : david vallado 719-573-2600 1 mar 2001
54
+ *
55
+ * inputs description range / units
56
+ * year - year 1900 .. 2100
57
+ * days - julian day of the year 0.0 .. 366.0
58
+ *
59
+ * outputs :
60
+ * mon - month 1 .. 12
61
+ * day - day 1 .. 28,29,30,31
62
+ * hr - hour 0 .. 23
63
+ * min - minute 0 .. 59
64
+ * sec - second 0.0 .. 59.999
65
+ *
66
+ * locals :
67
+ * dayofyr - day of year
68
+ * temp - temporary extended values
69
+ * inttemp - temporary int value
70
+ * i - index
71
+ * lmonth[12] - int array containing the number of days per month
72
+ *
73
+ * coupling :
74
+ * none.
75
+ * --------------------------------------------------------------------------- */
76
+ function days2mdhms(year, days) {
77
+ var lmonth = [31, year % 4 === 0 ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
78
+ var dayofyr = Math.floor(days);
79
+
80
+ // ----------------- find month and day of month ----------------
81
+ var i = 1;
82
+ var inttemp = 0;
83
+ while (dayofyr > inttemp + lmonth[i - 1] && i < 12) {
84
+ inttemp += lmonth[i - 1];
85
+ i += 1;
86
+ }
87
+
88
+ var mon = i;
89
+ var day = dayofyr - inttemp;
90
+
91
+ // ----------------- find hours minutes and seconds -------------
92
+ var temp = (days - dayofyr) * 24.0;
93
+ var hr = Math.floor(temp);
94
+ temp = (temp - hr) * 60.0;
95
+ var minute = Math.floor(temp);
96
+ var sec = (temp - minute) * 60.0;
97
+
98
+ return {
99
+ mon: mon,
100
+ day: day,
101
+ hr: hr,
102
+ minute: minute,
103
+ sec: sec
104
+ };
105
+ }
106
+
107
+ /* -----------------------------------------------------------------------------
108
+ *
109
+ * procedure jday
110
+ *
111
+ * this procedure finds the julian date given the year, month, day, and time.
112
+ * the julian date is defined by each elapsed day since noon, jan 1, 4713 bc.
113
+ *
114
+ * algorithm : calculate the answer in one step for efficiency
115
+ *
116
+ * author : david vallado 719-573-2600 1 mar 2001
117
+ *
118
+ * inputs description range / units
119
+ * year - year 1900 .. 2100
120
+ * mon - month 1 .. 12
121
+ * day - day 1 .. 28,29,30,31
122
+ * hr - universal time hour 0 .. 23
123
+ * min - universal time min 0 .. 59
124
+ * sec - universal time sec 0.0 .. 59.999
125
+ *
126
+ * outputs :
127
+ * jd - julian date days from 4713 bc
128
+ *
129
+ * locals :
130
+ * none.
131
+ *
132
+ * coupling :
133
+ * none.
134
+ *
135
+ * references :
136
+ * vallado 2007, 189, alg 14, ex 3-14
137
+ *
138
+ * --------------------------------------------------------------------------- */
139
+ function jdayInternal(year, mon, day, hr, minute, sec) {
140
+ var msec = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
141
+
142
+ return 367.0 * year - Math.floor(7 * (year + Math.floor((mon + 9) / 12.0)) * 0.25) + Math.floor(275 * mon / 9.0) + day + 1721013.5 + ((msec / 60000 + sec / 60.0 + minute) / 60.0 + hr) / 24.0 // ut in days
143
+ // # - 0.5*sgn(100.0*year + mon - 190002.5) + 0.5;
144
+ ;
145
+ }
146
+
147
+ function jday(year, mon, day, hr, minute, sec, msec) {
148
+ if (year instanceof Date) {
149
+ var date = year;
150
+ return jdayInternal(date.getUTCFullYear(), date.getUTCMonth() + 1, // Note, this function requires months in range 1-12.
151
+ date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());
152
+ }
153
+
154
+ return jdayInternal(year, mon, day, hr, minute, sec, msec);
155
+ }
156
+
157
+ /* -----------------------------------------------------------------------------
158
+ *
159
+ * procedure invjday
160
+ *
161
+ * this procedure finds the year, month, day, hour, minute and second
162
+ * given the julian date. tu can be ut1, tdt, tdb, etc.
163
+ *
164
+ * algorithm : set up starting values
165
+ * find leap year - use 1900 because 2000 is a leap year
166
+ * find the elapsed days through the year in a loop
167
+ * call routine to find each individual value
168
+ *
169
+ * author : david vallado 719-573-2600 1 mar 2001
170
+ *
171
+ * inputs description range / units
172
+ * jd - julian date days from 4713 bc
173
+ *
174
+ * outputs :
175
+ * year - year 1900 .. 2100
176
+ * mon - month 1 .. 12
177
+ * day - day 1 .. 28,29,30,31
178
+ * hr - hour 0 .. 23
179
+ * min - minute 0 .. 59
180
+ * sec - second 0.0 .. 59.999
181
+ *
182
+ * locals :
183
+ * days - day of year plus fractional
184
+ * portion of a day days
185
+ * tu - julian centuries from 0 h
186
+ * jan 0, 1900
187
+ * temp - temporary double values
188
+ * leapyrs - number of leap years from 1900
189
+ *
190
+ * coupling :
191
+ * days2mdhms - finds month, day, hour, minute and second given days and year
192
+ *
193
+ * references :
194
+ * vallado 2007, 208, alg 22, ex 3-13
195
+ * --------------------------------------------------------------------------- */
196
+ function invjday(jd, asArray) {
197
+ // --------------- find year and days of the year -
198
+ var temp = jd - 2415019.5;
199
+ var tu = temp / 365.25;
200
+ var year = 1900 + Math.floor(tu);
201
+ var leapyrs = Math.floor((year - 1901) * 0.25);
202
+
203
+ // optional nudge by 8.64x10-7 sec to get even outputs
204
+ var days = temp - ((year - 1900) * 365.0 + leapyrs) + 0.00000000001;
205
+
206
+ // ------------ check for case of beginning of a year -----------
207
+ if (days < 1.0) {
208
+ year -= 1;
209
+ leapyrs = Math.floor((year - 1901) * 0.25);
210
+ days = temp - ((year - 1900) * 365.0 + leapyrs);
211
+ }
212
+
213
+ // ----------------- find remaing data -------------------------
214
+ var mdhms = days2mdhms(year, days);
215
+
216
+ var mon = mdhms.mon,
217
+ day = mdhms.day,
218
+ hr = mdhms.hr,
219
+ minute = mdhms.minute;
220
+
221
+
222
+ var sec = mdhms.sec - 0.00000086400;
223
+
224
+ if (asArray) {
225
+ return [year, mon, day, hr, minute, Math.floor(sec)];
226
+ }
227
+
228
+ return new Date(Date.UTC(year, mon - 1, day, hr, minute, Math.floor(sec)));
229
+ }
230
+
231
+ /* -----------------------------------------------------------------------------
232
+ *
233
+ * procedure dpper
234
+ *
235
+ * this procedure provides deep space long period periodic contributions
236
+ * to the mean elements. by design, these periodics are zero at epoch.
237
+ * this used to be dscom which included initialization, but it's really a
238
+ * recurring function.
239
+ *
240
+ * author : david vallado 719-573-2600 28 jun 2005
241
+ *
242
+ * inputs :
243
+ * e3 -
244
+ * ee2 -
245
+ * peo -
246
+ * pgho -
247
+ * pho -
248
+ * pinco -
249
+ * plo -
250
+ * se2 , se3 , sgh2, sgh3, sgh4, sh2, sh3, si2, si3, sl2, sl3, sl4 -
251
+ * t -
252
+ * xh2, xh3, xi2, xi3, xl2, xl3, xl4 -
253
+ * zmol -
254
+ * zmos -
255
+ * ep - eccentricity 0.0 - 1.0
256
+ * inclo - inclination - needed for lyddane modification
257
+ * nodep - right ascension of ascending node
258
+ * argpp - argument of perigee
259
+ * mp - mean anomaly
260
+ *
261
+ * outputs :
262
+ * ep - eccentricity 0.0 - 1.0
263
+ * inclp - inclination
264
+ * nodep - right ascension of ascending node
265
+ * argpp - argument of perigee
266
+ * mp - mean anomaly
267
+ *
268
+ * locals :
269
+ * alfdp -
270
+ * betdp -
271
+ * cosip , sinip , cosop , sinop ,
272
+ * dalf -
273
+ * dbet -
274
+ * dls -
275
+ * f2, f3 -
276
+ * pe -
277
+ * pgh -
278
+ * ph -
279
+ * pinc -
280
+ * pl -
281
+ * sel , ses , sghl , sghs , shl , shs , sil , sinzf , sis ,
282
+ * sll , sls
283
+ * xls -
284
+ * xnoh -
285
+ * zf -
286
+ * zm -
287
+ *
288
+ * coupling :
289
+ * none.
290
+ *
291
+ * references :
292
+ * hoots, roehrich, norad spacetrack report #3 1980
293
+ * hoots, norad spacetrack report #6 1986
294
+ * hoots, schumacher and glover 2004
295
+ * vallado, crawford, hujsak, kelso 2006
296
+ ----------------------------------------------------------------------------*/
297
+ function dpper(satrec, options) {
298
+ var e3 = satrec.e3,
299
+ ee2 = satrec.ee2,
300
+ peo = satrec.peo,
301
+ pgho = satrec.pgho,
302
+ pho = satrec.pho,
303
+ pinco = satrec.pinco,
304
+ plo = satrec.plo,
305
+ se2 = satrec.se2,
306
+ se3 = satrec.se3,
307
+ sgh2 = satrec.sgh2,
308
+ sgh3 = satrec.sgh3,
309
+ sgh4 = satrec.sgh4,
310
+ sh2 = satrec.sh2,
311
+ sh3 = satrec.sh3,
312
+ si2 = satrec.si2,
313
+ si3 = satrec.si3,
314
+ sl2 = satrec.sl2,
315
+ sl3 = satrec.sl3,
316
+ sl4 = satrec.sl4,
317
+ t = satrec.t,
318
+ xgh2 = satrec.xgh2,
319
+ xgh3 = satrec.xgh3,
320
+ xgh4 = satrec.xgh4,
321
+ xh2 = satrec.xh2,
322
+ xh3 = satrec.xh3,
323
+ xi2 = satrec.xi2,
324
+ xi3 = satrec.xi3,
325
+ xl2 = satrec.xl2,
326
+ xl3 = satrec.xl3,
327
+ xl4 = satrec.xl4,
328
+ zmol = satrec.zmol,
329
+ zmos = satrec.zmos;
330
+ var init = options.init,
331
+ opsmode = options.opsmode;
332
+ var ep = options.ep,
333
+ inclp = options.inclp,
334
+ nodep = options.nodep,
335
+ argpp = options.argpp,
336
+ mp = options.mp;
337
+
338
+ // Copy satellite attributes into local variables for convenience
339
+ // and symmetry in writing formulae.
340
+
341
+ var alfdp = void 0;
342
+ var betdp = void 0;
343
+ var cosip = void 0;
344
+ var sinip = void 0;
345
+ var cosop = void 0;
346
+ var sinop = void 0;
347
+ var dalf = void 0;
348
+ var dbet = void 0;
349
+ var dls = void 0;
350
+ var f2 = void 0;
351
+ var f3 = void 0;
352
+ var pe = void 0;
353
+ var pgh = void 0;
354
+ var ph = void 0;
355
+ var pinc = void 0;
356
+ var pl = void 0;
357
+ var sinzf = void 0;
358
+ var xls = void 0;
359
+ var xnoh = void 0;
360
+ var zf = void 0;
361
+ var zm = void 0;
362
+
363
+ // ---------------------- constants -----------------------------
364
+ var zns = 1.19459e-5;
365
+ var zes = 0.01675;
366
+ var znl = 1.5835218e-4;
367
+ var zel = 0.05490;
368
+
369
+ // --------------- calculate time varying periodics -----------
370
+ zm = zmos + zns * t;
371
+
372
+ // be sure that the initial call has time set to zero
373
+ if (init === 'y') {
374
+ zm = zmos;
375
+ }
376
+ zf = zm + 2.0 * zes * Math.sin(zm);
377
+ sinzf = Math.sin(zf);
378
+ f2 = 0.5 * sinzf * sinzf - 0.25;
379
+ f3 = -0.5 * sinzf * Math.cos(zf);
380
+
381
+ var ses = se2 * f2 + se3 * f3;
382
+ var sis = si2 * f2 + si3 * f3;
383
+ var sls = sl2 * f2 + sl3 * f3 + sl4 * sinzf;
384
+ var sghs = sgh2 * f2 + sgh3 * f3 + sgh4 * sinzf;
385
+ var shs = sh2 * f2 + sh3 * f3;
386
+
387
+ zm = zmol + znl * t;
388
+ if (init === 'y') {
389
+ zm = zmol;
390
+ }
391
+
392
+ zf = zm + 2.0 * zel * Math.sin(zm);
393
+ sinzf = Math.sin(zf);
394
+ f2 = 0.5 * sinzf * sinzf - 0.25;
395
+ f3 = -0.5 * sinzf * Math.cos(zf);
396
+
397
+ var sel = ee2 * f2 + e3 * f3;
398
+ var sil = xi2 * f2 + xi3 * f3;
399
+ var sll = xl2 * f2 + xl3 * f3 + xl4 * sinzf;
400
+ var sghl = xgh2 * f2 + xgh3 * f3 + xgh4 * sinzf;
401
+ var shll = xh2 * f2 + xh3 * f3;
402
+
403
+ pe = ses + sel;
404
+ pinc = sis + sil;
405
+ pl = sls + sll;
406
+ pgh = sghs + sghl;
407
+ ph = shs + shll;
408
+
409
+ if (init === 'n') {
410
+ pe -= peo;
411
+ pinc -= pinco;
412
+ pl -= plo;
413
+ pgh -= pgho;
414
+ ph -= pho;
415
+ inclp += pinc;
416
+ ep += pe;
417
+ sinip = Math.sin(inclp);
418
+ cosip = Math.cos(inclp);
419
+
420
+ /* ----------------- apply periodics directly ------------ */
421
+ // sgp4fix for lyddane choice
422
+ // strn3 used original inclination - this is technically feasible
423
+ // gsfc used perturbed inclination - also technically feasible
424
+ // probably best to readjust the 0.2 limit value and limit discontinuity
425
+ // 0.2 rad = 11.45916 deg
426
+ // use next line for original strn3 approach and original inclination
427
+ // if (inclo >= 0.2)
428
+ // use next line for gsfc version and perturbed inclination
429
+ if (inclp >= 0.2) {
430
+ ph /= sinip;
431
+ pgh -= cosip * ph;
432
+ argpp += pgh;
433
+ nodep += ph;
434
+ mp += pl;
435
+ } else {
436
+ // ---- apply periodics with lyddane modification ----
437
+ sinop = Math.sin(nodep);
438
+ cosop = Math.cos(nodep);
439
+ alfdp = sinip * sinop;
440
+ betdp = sinip * cosop;
441
+ dalf = ph * cosop + pinc * cosip * sinop;
442
+ dbet = -ph * sinop + pinc * cosip * cosop;
443
+ alfdp += dalf;
444
+ betdp += dbet;
445
+ nodep %= twoPi;
446
+
447
+ // sgp4fix for afspc written intrinsic functions
448
+ // nodep used without a trigonometric function ahead
449
+ if (nodep < 0.0 && opsmode === 'a') {
450
+ nodep += twoPi;
451
+ }
452
+ xls = mp + argpp + cosip * nodep;
453
+ dls = pl + pgh - pinc * nodep * sinip;
454
+ xls += dls;
455
+ xnoh = nodep;
456
+ nodep = Math.atan2(alfdp, betdp);
457
+
458
+ // sgp4fix for afspc written intrinsic functions
459
+ // nodep used without a trigonometric function ahead
460
+ if (nodep < 0.0 && opsmode === 'a') {
461
+ nodep += twoPi;
462
+ }
463
+ if (Math.abs(xnoh - nodep) > pi) {
464
+ if (nodep < xnoh) {
465
+ nodep += twoPi;
466
+ } else {
467
+ nodep -= twoPi;
468
+ }
469
+ }
470
+ mp += pl;
471
+ argpp = xls - mp - cosip * nodep;
472
+ }
473
+ }
474
+
475
+ return {
476
+ ep: ep,
477
+ inclp: inclp,
478
+ nodep: nodep,
479
+ argpp: argpp,
480
+ mp: mp
481
+ };
482
+ }
483
+
484
+ /*-----------------------------------------------------------------------------
485
+ *
486
+ * procedure dscom
487
+ *
488
+ * this procedure provides deep space common items used by both the secular
489
+ * and periodics subroutines. input is provided as shown. this routine
490
+ * used to be called dpper, but the functions inside weren't well organized.
491
+ *
492
+ * author : david vallado 719-573-2600 28 jun 2005
493
+ *
494
+ * inputs :
495
+ * epoch -
496
+ * ep - eccentricity
497
+ * argpp - argument of perigee
498
+ * tc -
499
+ * inclp - inclination
500
+ * nodep - right ascension of ascending node
501
+ * np - mean motion
502
+ *
503
+ * outputs :
504
+ * sinim , cosim , sinomm , cosomm , snodm , cnodm
505
+ * day -
506
+ * e3 -
507
+ * ee2 -
508
+ * em - eccentricity
509
+ * emsq - eccentricity squared
510
+ * gam -
511
+ * peo -
512
+ * pgho -
513
+ * pho -
514
+ * pinco -
515
+ * plo -
516
+ * rtemsq -
517
+ * se2, se3 -
518
+ * sgh2, sgh3, sgh4 -
519
+ * sh2, sh3, si2, si3, sl2, sl3, sl4 -
520
+ * s1, s2, s3, s4, s5, s6, s7 -
521
+ * ss1, ss2, ss3, ss4, ss5, ss6, ss7, sz1, sz2, sz3 -
522
+ * sz11, sz12, sz13, sz21, sz22, sz23, sz31, sz32, sz33 -
523
+ * xgh2, xgh3, xgh4, xh2, xh3, xi2, xi3, xl2, xl3, xl4 -
524
+ * nm - mean motion
525
+ * z1, z2, z3, z11, z12, z13, z21, z22, z23, z31, z32, z33 -
526
+ * zmol -
527
+ * zmos -
528
+ *
529
+ * locals :
530
+ * a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -
531
+ * betasq -
532
+ * cc -
533
+ * ctem, stem -
534
+ * x1, x2, x3, x4, x5, x6, x7, x8 -
535
+ * xnodce -
536
+ * xnoi -
537
+ * zcosg , zsing , zcosgl , zsingl , zcosh , zsinh , zcoshl , zsinhl ,
538
+ * zcosi , zsini , zcosil , zsinil ,
539
+ * zx -
540
+ * zy -
541
+ *
542
+ * coupling :
543
+ * none.
544
+ *
545
+ * references :
546
+ * hoots, roehrich, norad spacetrack report #3 1980
547
+ * hoots, norad spacetrack report #6 1986
548
+ * hoots, schumacher and glover 2004
549
+ * vallado, crawford, hujsak, kelso 2006
550
+ ----------------------------------------------------------------------------*/
551
+ function dscom(options) {
552
+ var epoch = options.epoch,
553
+ ep = options.ep,
554
+ argpp = options.argpp,
555
+ tc = options.tc,
556
+ inclp = options.inclp,
557
+ nodep = options.nodep,
558
+ np = options.np;
559
+
560
+
561
+ var a1 = void 0;
562
+ var a2 = void 0;
563
+ var a3 = void 0;
564
+ var a4 = void 0;
565
+ var a5 = void 0;
566
+ var a6 = void 0;
567
+ var a7 = void 0;
568
+ var a8 = void 0;
569
+ var a9 = void 0;
570
+ var a10 = void 0;
571
+ var cc = void 0;
572
+ var x1 = void 0;
573
+ var x2 = void 0;
574
+ var x3 = void 0;
575
+ var x4 = void 0;
576
+ var x5 = void 0;
577
+ var x6 = void 0;
578
+ var x7 = void 0;
579
+ var x8 = void 0;
580
+ var zcosg = void 0;
581
+ var zsing = void 0;
582
+ var zcosh = void 0;
583
+ var zsinh = void 0;
584
+ var zcosi = void 0;
585
+ var zsini = void 0;
586
+
587
+ var ss1 = void 0;
588
+ var ss2 = void 0;
589
+ var ss3 = void 0;
590
+ var ss4 = void 0;
591
+ var ss5 = void 0;
592
+ var ss6 = void 0;
593
+ var ss7 = void 0;
594
+ var sz1 = void 0;
595
+ var sz2 = void 0;
596
+ var sz3 = void 0;
597
+ var sz11 = void 0;
598
+ var sz12 = void 0;
599
+ var sz13 = void 0;
600
+ var sz21 = void 0;
601
+ var sz22 = void 0;
602
+ var sz23 = void 0;
603
+ var sz31 = void 0;
604
+ var sz32 = void 0;
605
+ var sz33 = void 0;
606
+ var s1 = void 0;
607
+ var s2 = void 0;
608
+ var s3 = void 0;
609
+ var s4 = void 0;
610
+ var s5 = void 0;
611
+ var s6 = void 0;
612
+ var s7 = void 0;
613
+ var z1 = void 0;
614
+ var z2 = void 0;
615
+ var z3 = void 0;
616
+ var z11 = void 0;
617
+ var z12 = void 0;
618
+ var z13 = void 0;
619
+ var z21 = void 0;
620
+ var z22 = void 0;
621
+ var z23 = void 0;
622
+ var z31 = void 0;
623
+ var z32 = void 0;
624
+ var z33 = void 0;
625
+
626
+ // -------------------------- constants -------------------------
627
+ var zes = 0.01675;
628
+ var zel = 0.05490;
629
+ var c1ss = 2.9864797e-6;
630
+ var c1l = 4.7968065e-7;
631
+ var zsinis = 0.39785416;
632
+ var zcosis = 0.91744867;
633
+ var zcosgs = 0.1945905;
634
+ var zsings = -0.98088458;
635
+
636
+ // --------------------- local variables ------------------------
637
+ var nm = np;
638
+ var em = ep;
639
+ var snodm = Math.sin(nodep);
640
+ var cnodm = Math.cos(nodep);
641
+ var sinomm = Math.sin(argpp);
642
+ var cosomm = Math.cos(argpp);
643
+ var sinim = Math.sin(inclp);
644
+ var cosim = Math.cos(inclp);
645
+ var emsq = em * em;
646
+ var betasq = 1.0 - emsq;
647
+ var rtemsq = Math.sqrt(betasq);
648
+
649
+ // ----------------- initialize lunar solar terms ---------------
650
+ var peo = 0.0;
651
+ var pinco = 0.0;
652
+ var plo = 0.0;
653
+ var pgho = 0.0;
654
+ var pho = 0.0;
655
+ var day = epoch + 18261.5 + tc / 1440.0;
656
+ var xnodce = (4.5236020 - 9.2422029e-4 * day) % twoPi;
657
+ var stem = Math.sin(xnodce);
658
+ var ctem = Math.cos(xnodce);
659
+ var zcosil = 0.91375164 - 0.03568096 * ctem;
660
+ var zsinil = Math.sqrt(1.0 - zcosil * zcosil);
661
+ var zsinhl = 0.089683511 * stem / zsinil;
662
+ var zcoshl = Math.sqrt(1.0 - zsinhl * zsinhl);
663
+ var gam = 5.8351514 + 0.0019443680 * day;
664
+ var zx = 0.39785416 * stem / zsinil;
665
+ var zy = zcoshl * ctem + 0.91744867 * zsinhl * stem;
666
+ zx = Math.atan2(zx, zy);
667
+ zx += gam - xnodce;
668
+ var zcosgl = Math.cos(zx);
669
+ var zsingl = Math.sin(zx);
670
+
671
+ // ------------------------- do solar terms ---------------------
672
+ zcosg = zcosgs;
673
+ zsing = zsings;
674
+ zcosi = zcosis;
675
+ zsini = zsinis;
676
+ zcosh = cnodm;
677
+ zsinh = snodm;
678
+ cc = c1ss;
679
+ var xnoi = 1.0 / nm;
680
+
681
+ var lsflg = 0;
682
+ while (lsflg < 2) {
683
+ lsflg += 1;
684
+ a1 = zcosg * zcosh + zsing * zcosi * zsinh;
685
+ a3 = -zsing * zcosh + zcosg * zcosi * zsinh;
686
+ a7 = -zcosg * zsinh + zsing * zcosi * zcosh;
687
+ a8 = zsing * zsini;
688
+ a9 = zsing * zsinh + zcosg * zcosi * zcosh;
689
+ a10 = zcosg * zsini;
690
+ a2 = cosim * a7 + sinim * a8;
691
+ a4 = cosim * a9 + sinim * a10;
692
+ a5 = -sinim * a7 + cosim * a8;
693
+ a6 = -sinim * a9 + cosim * a10;
694
+
695
+ x1 = a1 * cosomm + a2 * sinomm;
696
+ x2 = a3 * cosomm + a4 * sinomm;
697
+ x3 = -a1 * sinomm + a2 * cosomm;
698
+ x4 = -a3 * sinomm + a4 * cosomm;
699
+ x5 = a5 * sinomm;
700
+ x6 = a6 * sinomm;
701
+ x7 = a5 * cosomm;
702
+ x8 = a6 * cosomm;
703
+
704
+ z31 = 12.0 * x1 * x1 - 3.0 * x3 * x3;
705
+ z32 = 24.0 * x1 * x2 - 6.0 * x3 * x4;
706
+ z33 = 12.0 * x2 * x2 - 3.0 * x4 * x4;
707
+
708
+ z1 = 3.0 * (a1 * a1 + a2 * a2) + z31 * emsq;
709
+ z2 = 6.0 * (a1 * a3 + a2 * a4) + z32 * emsq;
710
+ z3 = 3.0 * (a3 * a3 + a4 * a4) + z33 * emsq;
711
+
712
+ z11 = -6.0 * a1 * a5 + emsq * (-24.0 * x1 * x7 - 6.0 * x3 * x5);
713
+ z12 = -6.0 * (a1 * a6 + a3 * a5) + emsq * (-24.0 * (x2 * x7 + x1 * x8) + -6.0 * (x3 * x6 + x4 * x5));
714
+
715
+ z13 = -6.0 * a3 * a6 + emsq * (-24.0 * x2 * x8 - 6.0 * x4 * x6);
716
+
717
+ z21 = 6.0 * a2 * a5 + emsq * (24.0 * x1 * x5 - 6.0 * x3 * x7);
718
+ z22 = 6.0 * (a4 * a5 + a2 * a6) + emsq * (24.0 * (x2 * x5 + x1 * x6) - 6.0 * (x4 * x7 + x3 * x8));
719
+ z23 = 6.0 * a4 * a6 + emsq * (24.0 * x2 * x6 - 6.0 * x4 * x8);
720
+
721
+ z1 = z1 + z1 + betasq * z31;
722
+ z2 = z2 + z2 + betasq * z32;
723
+ z3 = z3 + z3 + betasq * z33;
724
+ s3 = cc * xnoi;
725
+ s2 = -0.5 * s3 / rtemsq;
726
+ s4 = s3 * rtemsq;
727
+ s1 = -15.0 * em * s4;
728
+ s5 = x1 * x3 + x2 * x4;
729
+ s6 = x2 * x3 + x1 * x4;
730
+ s7 = x2 * x4 - x1 * x3;
731
+
732
+ // ----------------------- do lunar terms -------------------
733
+ if (lsflg === 1) {
734
+ ss1 = s1;
735
+ ss2 = s2;
736
+ ss3 = s3;
737
+ ss4 = s4;
738
+ ss5 = s5;
739
+ ss6 = s6;
740
+ ss7 = s7;
741
+ sz1 = z1;
742
+ sz2 = z2;
743
+ sz3 = z3;
744
+ sz11 = z11;
745
+ sz12 = z12;
746
+ sz13 = z13;
747
+ sz21 = z21;
748
+ sz22 = z22;
749
+ sz23 = z23;
750
+ sz31 = z31;
751
+ sz32 = z32;
752
+ sz33 = z33;
753
+ zcosg = zcosgl;
754
+ zsing = zsingl;
755
+ zcosi = zcosil;
756
+ zsini = zsinil;
757
+ zcosh = zcoshl * cnodm + zsinhl * snodm;
758
+ zsinh = snodm * zcoshl - cnodm * zsinhl;
759
+ cc = c1l;
760
+ }
761
+ }
762
+
763
+ var zmol = (4.7199672 + (0.22997150 * day - gam)) % twoPi;
764
+ var zmos = (6.2565837 + 0.017201977 * day) % twoPi;
765
+
766
+ // ------------------------ do solar terms ----------------------
767
+ var se2 = 2.0 * ss1 * ss6;
768
+ var se3 = 2.0 * ss1 * ss7;
769
+ var si2 = 2.0 * ss2 * sz12;
770
+ var si3 = 2.0 * ss2 * (sz13 - sz11);
771
+ var sl2 = -2.0 * ss3 * sz2;
772
+ var sl3 = -2.0 * ss3 * (sz3 - sz1);
773
+ var sl4 = -2.0 * ss3 * (-21.0 - 9.0 * emsq) * zes;
774
+ var sgh2 = 2.0 * ss4 * sz32;
775
+ var sgh3 = 2.0 * ss4 * (sz33 - sz31);
776
+ var sgh4 = -18.0 * ss4 * zes;
777
+ var sh2 = -2.0 * ss2 * sz22;
778
+ var sh3 = -2.0 * ss2 * (sz23 - sz21);
779
+
780
+ // ------------------------ do lunar terms ----------------------
781
+ var ee2 = 2.0 * s1 * s6;
782
+ var e3 = 2.0 * s1 * s7;
783
+ var xi2 = 2.0 * s2 * z12;
784
+ var xi3 = 2.0 * s2 * (z13 - z11);
785
+ var xl2 = -2.0 * s3 * z2;
786
+ var xl3 = -2.0 * s3 * (z3 - z1);
787
+ var xl4 = -2.0 * s3 * (-21.0 - 9.0 * emsq) * zel;
788
+ var xgh2 = 2.0 * s4 * z32;
789
+ var xgh3 = 2.0 * s4 * (z33 - z31);
790
+ var xgh4 = -18.0 * s4 * zel;
791
+ var xh2 = -2.0 * s2 * z22;
792
+ var xh3 = -2.0 * s2 * (z23 - z21);
793
+
794
+ return {
795
+ snodm: snodm,
796
+ cnodm: cnodm,
797
+ sinim: sinim,
798
+ cosim: cosim,
799
+ sinomm: sinomm,
800
+
801
+ cosomm: cosomm,
802
+ day: day,
803
+ e3: e3,
804
+ ee2: ee2,
805
+ em: em,
806
+
807
+ emsq: emsq,
808
+ gam: gam,
809
+ peo: peo,
810
+ pgho: pgho,
811
+ pho: pho,
812
+
813
+ pinco: pinco,
814
+ plo: plo,
815
+ rtemsq: rtemsq,
816
+ se2: se2,
817
+ se3: se3,
818
+
819
+ sgh2: sgh2,
820
+ sgh3: sgh3,
821
+ sgh4: sgh4,
822
+ sh2: sh2,
823
+ sh3: sh3,
824
+
825
+ si2: si2,
826
+ si3: si3,
827
+ sl2: sl2,
828
+ sl3: sl3,
829
+ sl4: sl4,
830
+
831
+ s1: s1,
832
+ s2: s2,
833
+ s3: s3,
834
+ s4: s4,
835
+ s5: s5,
836
+
837
+ s6: s6,
838
+ s7: s7,
839
+ ss1: ss1,
840
+ ss2: ss2,
841
+ ss3: ss3,
842
+
843
+ ss4: ss4,
844
+ ss5: ss5,
845
+ ss6: ss6,
846
+ ss7: ss7,
847
+ sz1: sz1,
848
+
849
+ sz2: sz2,
850
+ sz3: sz3,
851
+ sz11: sz11,
852
+ sz12: sz12,
853
+ sz13: sz13,
854
+
855
+ sz21: sz21,
856
+ sz22: sz22,
857
+ sz23: sz23,
858
+ sz31: sz31,
859
+ sz32: sz32,
860
+
861
+ sz33: sz33,
862
+ xgh2: xgh2,
863
+ xgh3: xgh3,
864
+ xgh4: xgh4,
865
+ xh2: xh2,
866
+
867
+ xh3: xh3,
868
+ xi2: xi2,
869
+ xi3: xi3,
870
+ xl2: xl2,
871
+ xl3: xl3,
872
+
873
+ xl4: xl4,
874
+ nm: nm,
875
+ z1: z1,
876
+ z2: z2,
877
+ z3: z3,
878
+
879
+ z11: z11,
880
+ z12: z12,
881
+ z13: z13,
882
+ z21: z21,
883
+ z22: z22,
884
+
885
+ z23: z23,
886
+ z31: z31,
887
+ z32: z32,
888
+ z33: z33,
889
+ zmol: zmol,
890
+
891
+ zmos: zmos
892
+ };
893
+ }
894
+
895
+ /*-----------------------------------------------------------------------------
896
+ *
897
+ * procedure dsinit
898
+ *
899
+ * this procedure provides deep space contributions to mean motion dot due
900
+ * to geopotential resonance with half day and one day orbits.
901
+ *
902
+ * author : david vallado 719-573-2600 28 jun 2005
903
+ *
904
+ * inputs :
905
+ * cosim, sinim-
906
+ * emsq - eccentricity squared
907
+ * argpo - argument of perigee
908
+ * s1, s2, s3, s4, s5 -
909
+ * ss1, ss2, ss3, ss4, ss5 -
910
+ * sz1, sz3, sz11, sz13, sz21, sz23, sz31, sz33 -
911
+ * t - time
912
+ * tc -
913
+ * gsto - greenwich sidereal time rad
914
+ * mo - mean anomaly
915
+ * mdot - mean anomaly dot (rate)
916
+ * no - mean motion
917
+ * nodeo - right ascension of ascending node
918
+ * nodedot - right ascension of ascending node dot (rate)
919
+ * xpidot -
920
+ * z1, z3, z11, z13, z21, z23, z31, z33 -
921
+ * eccm - eccentricity
922
+ * argpm - argument of perigee
923
+ * inclm - inclination
924
+ * mm - mean anomaly
925
+ * xn - mean motion
926
+ * nodem - right ascension of ascending node
927
+ *
928
+ * outputs :
929
+ * em - eccentricity
930
+ * argpm - argument of perigee
931
+ * inclm - inclination
932
+ * mm - mean anomaly
933
+ * nm - mean motion
934
+ * nodem - right ascension of ascending node
935
+ * irez - flag for resonance 0-none, 1-one day, 2-half day
936
+ * atime -
937
+ * d2201, d2211, d3210, d3222, d4410, d4422, d5220, d5232, d5421, d5433 -
938
+ * dedt -
939
+ * didt -
940
+ * dmdt -
941
+ * dndt -
942
+ * dnodt -
943
+ * domdt -
944
+ * del1, del2, del3 -
945
+ * ses , sghl , sghs , sgs , shl , shs , sis , sls
946
+ * theta -
947
+ * xfact -
948
+ * xlamo -
949
+ * xli -
950
+ * xni
951
+ *
952
+ * locals :
953
+ * ainv2 -
954
+ * aonv -
955
+ * cosisq -
956
+ * eoc -
957
+ * f220, f221, f311, f321, f322, f330, f441, f442, f522, f523, f542, f543 -
958
+ * g200, g201, g211, g300, g310, g322, g410, g422, g520, g521, g532, g533 -
959
+ * sini2 -
960
+ * temp -
961
+ * temp1 -
962
+ * theta -
963
+ * xno2 -
964
+ *
965
+ * coupling :
966
+ * getgravconst
967
+ *
968
+ * references :
969
+ * hoots, roehrich, norad spacetrack report #3 1980
970
+ * hoots, norad spacetrack report #6 1986
971
+ * hoots, schumacher and glover 2004
972
+ * vallado, crawford, hujsak, kelso 2006
973
+ ----------------------------------------------------------------------------*/
974
+ function dsinit(options) {
975
+ var cosim = options.cosim,
976
+ argpo = options.argpo,
977
+ s1 = options.s1,
978
+ s2 = options.s2,
979
+ s3 = options.s3,
980
+ s4 = options.s4,
981
+ s5 = options.s5,
982
+ sinim = options.sinim,
983
+ ss1 = options.ss1,
984
+ ss2 = options.ss2,
985
+ ss3 = options.ss3,
986
+ ss4 = options.ss4,
987
+ ss5 = options.ss5,
988
+ sz1 = options.sz1,
989
+ sz3 = options.sz3,
990
+ sz11 = options.sz11,
991
+ sz13 = options.sz13,
992
+ sz21 = options.sz21,
993
+ sz23 = options.sz23,
994
+ sz31 = options.sz31,
995
+ sz33 = options.sz33,
996
+ t = options.t,
997
+ tc = options.tc,
998
+ gsto = options.gsto,
999
+ mo = options.mo,
1000
+ mdot = options.mdot,
1001
+ no = options.no,
1002
+ nodeo = options.nodeo,
1003
+ nodedot = options.nodedot,
1004
+ xpidot = options.xpidot,
1005
+ z1 = options.z1,
1006
+ z3 = options.z3,
1007
+ z11 = options.z11,
1008
+ z13 = options.z13,
1009
+ z21 = options.z21,
1010
+ z23 = options.z23,
1011
+ z31 = options.z31,
1012
+ z33 = options.z33,
1013
+ ecco = options.ecco,
1014
+ eccsq = options.eccsq;
1015
+ var emsq = options.emsq,
1016
+ em = options.em,
1017
+ argpm = options.argpm,
1018
+ inclm = options.inclm,
1019
+ mm = options.mm,
1020
+ nm = options.nm,
1021
+ nodem = options.nodem,
1022
+ irez = options.irez,
1023
+ atime = options.atime,
1024
+ d2201 = options.d2201,
1025
+ d2211 = options.d2211,
1026
+ d3210 = options.d3210,
1027
+ d3222 = options.d3222,
1028
+ d4410 = options.d4410,
1029
+ d4422 = options.d4422,
1030
+ d5220 = options.d5220,
1031
+ d5232 = options.d5232,
1032
+ d5421 = options.d5421,
1033
+ d5433 = options.d5433,
1034
+ dedt = options.dedt,
1035
+ didt = options.didt,
1036
+ dmdt = options.dmdt,
1037
+ dnodt = options.dnodt,
1038
+ domdt = options.domdt,
1039
+ del1 = options.del1,
1040
+ del2 = options.del2,
1041
+ del3 = options.del3,
1042
+ xfact = options.xfact,
1043
+ xlamo = options.xlamo,
1044
+ xli = options.xli,
1045
+ xni = options.xni;
1046
+
1047
+
1048
+ var f220 = void 0;
1049
+ var f221 = void 0;
1050
+ var f311 = void 0;
1051
+ var f321 = void 0;
1052
+ var f322 = void 0;
1053
+ var f330 = void 0;
1054
+ var f441 = void 0;
1055
+ var f442 = void 0;
1056
+ var f522 = void 0;
1057
+ var f523 = void 0;
1058
+ var f542 = void 0;
1059
+ var f543 = void 0;
1060
+ var g200 = void 0;
1061
+ var g201 = void 0;
1062
+ var g211 = void 0;
1063
+ var g300 = void 0;
1064
+ var g310 = void 0;
1065
+ var g322 = void 0;
1066
+ var g410 = void 0;
1067
+ var g422 = void 0;
1068
+ var g520 = void 0;
1069
+ var g521 = void 0;
1070
+ var g532 = void 0;
1071
+ var g533 = void 0;
1072
+ var sini2 = void 0;
1073
+ var temp = void 0;
1074
+ var temp1 = void 0;
1075
+ var xno2 = void 0;
1076
+ var ainv2 = void 0;
1077
+ var aonv = void 0;
1078
+ var cosisq = void 0;
1079
+ var eoc = void 0;
1080
+
1081
+ var q22 = 1.7891679e-6;
1082
+ var q31 = 2.1460748e-6;
1083
+ var q33 = 2.2123015e-7;
1084
+ var root22 = 1.7891679e-6;
1085
+ var root44 = 7.3636953e-9;
1086
+ var root54 = 2.1765803e-9;
1087
+ var rptim = 4.37526908801129966e-3; // equates to 7.29211514668855e-5 rad/sec
1088
+ var root32 = 3.7393792e-7;
1089
+ var root52 = 1.1428639e-7;
1090
+ var znl = 1.5835218e-4;
1091
+ var zns = 1.19459e-5;
1092
+
1093
+ // -------------------- deep space initialization ------------
1094
+ irez = 0;
1095
+ if (nm < 0.0052359877 && nm > 0.0034906585) {
1096
+ irez = 1;
1097
+ }
1098
+ if (nm >= 8.26e-3 && nm <= 9.24e-3 && em >= 0.5) {
1099
+ irez = 2;
1100
+ }
1101
+
1102
+ // ------------------------ do solar terms -------------------
1103
+ var ses = ss1 * zns * ss5;
1104
+ var sis = ss2 * zns * (sz11 + sz13);
1105
+ var sls = -zns * ss3 * (sz1 + sz3 - 14.0 - 6.0 * emsq);
1106
+ var sghs = ss4 * zns * (sz31 + sz33 - 6.0);
1107
+ var shs = -zns * ss2 * (sz21 + sz23);
1108
+
1109
+ // sgp4fix for 180 deg incl
1110
+ if (inclm < 5.2359877e-2 || inclm > pi - 5.2359877e-2) {
1111
+ shs = 0.0;
1112
+ }
1113
+ if (sinim !== 0.0) {
1114
+ shs /= sinim;
1115
+ }
1116
+ var sgs = sghs - cosim * shs;
1117
+
1118
+ // ------------------------- do lunar terms ------------------
1119
+ dedt = ses + s1 * znl * s5;
1120
+ didt = sis + s2 * znl * (z11 + z13);
1121
+ dmdt = sls - znl * s3 * (z1 + z3 - 14.0 - 6.0 * emsq);
1122
+ var sghl = s4 * znl * (z31 + z33 - 6.0);
1123
+ var shll = -znl * s2 * (z21 + z23);
1124
+
1125
+ // sgp4fix for 180 deg incl
1126
+ if (inclm < 5.2359877e-2 || inclm > pi - 5.2359877e-2) {
1127
+ shll = 0.0;
1128
+ }
1129
+ domdt = sgs + sghl;
1130
+ dnodt = shs;
1131
+ if (sinim !== 0.0) {
1132
+ domdt -= cosim / sinim * shll;
1133
+ dnodt += shll / sinim;
1134
+ }
1135
+
1136
+ // ----------- calculate deep space resonance effects --------
1137
+ var dndt = 0.0;
1138
+ var theta = (gsto + tc * rptim) % twoPi;
1139
+ em += dedt * t;
1140
+ inclm += didt * t;
1141
+ argpm += domdt * t;
1142
+ nodem += dnodt * t;
1143
+ mm += dmdt * t;
1144
+
1145
+ // sgp4fix for negative inclinations
1146
+ // the following if statement should be commented out
1147
+ // if (inclm < 0.0)
1148
+ // {
1149
+ // inclm = -inclm;
1150
+ // argpm = argpm - pi;
1151
+ // nodem = nodem + pi;
1152
+ // }
1153
+
1154
+ // -------------- initialize the resonance terms -------------
1155
+ if (irez !== 0) {
1156
+ aonv = Math.pow(nm / xke, x2o3);
1157
+
1158
+ // ---------- geopotential resonance for 12 hour orbits ------
1159
+ if (irez === 2) {
1160
+ cosisq = cosim * cosim;
1161
+ var emo = em;
1162
+ em = ecco;
1163
+ var emsqo = emsq;
1164
+ emsq = eccsq;
1165
+ eoc = em * emsq;
1166
+ g201 = -0.306 - (em - 0.64) * 0.440;
1167
+
1168
+ if (em <= 0.65) {
1169
+ g211 = 3.616 - 13.2470 * em + 16.2900 * emsq;
1170
+ g310 = -19.302 + 117.3900 * em - 228.4190 * emsq + 156.5910 * eoc;
1171
+ g322 = -18.9068 + 109.7927 * em - 214.6334 * emsq + 146.5816 * eoc;
1172
+ g410 = -41.122 + 242.6940 * em - 471.0940 * emsq + 313.9530 * eoc;
1173
+ g422 = -146.407 + 841.8800 * em - 1629.014 * emsq + 1083.4350 * eoc;
1174
+ g520 = -532.114 + 3017.977 * em - 5740.032 * emsq + 3708.2760 * eoc;
1175
+ } else {
1176
+ g211 = -72.099 + 331.819 * em - 508.738 * emsq + 266.724 * eoc;
1177
+ g310 = -346.844 + 1582.851 * em - 2415.925 * emsq + 1246.113 * eoc;
1178
+ g322 = -342.585 + 1554.908 * em - 2366.899 * emsq + 1215.972 * eoc;
1179
+ g410 = -1052.797 + 4758.686 * em - 7193.992 * emsq + 3651.957 * eoc;
1180
+ g422 = -3581.690 + 16178.110 * em - 24462.770 * emsq + 12422.520 * eoc;
1181
+ if (em > 0.715) {
1182
+ g520 = -5149.66 + 29936.92 * em - 54087.36 * emsq + 31324.56 * eoc;
1183
+ } else {
1184
+ g520 = 1464.74 - 4664.75 * em + 3763.64 * emsq;
1185
+ }
1186
+ }
1187
+ if (em < 0.7) {
1188
+ g533 = -919.22770 + 4988.6100 * em - 9064.7700 * emsq + 5542.21 * eoc;
1189
+ g521 = -822.71072 + 4568.6173 * em - 8491.4146 * emsq + 5337.524 * eoc;
1190
+ g532 = -853.66600 + 4690.2500 * em - 8624.7700 * emsq + 5341.4 * eoc;
1191
+ } else {
1192
+ g533 = -37995.780 + 161616.52 * em - 229838.20 * emsq + 109377.94 * eoc;
1193
+ g521 = -51752.104 + 218913.95 * em - 309468.16 * emsq + 146349.42 * eoc;
1194
+ g532 = -40023.880 + 170470.89 * em - 242699.48 * emsq + 115605.82 * eoc;
1195
+ }
1196
+ sini2 = sinim * sinim;
1197
+ f220 = 0.75 * (1.0 + 2.0 * cosim + cosisq);
1198
+ f221 = 1.5 * sini2;
1199
+ f321 = 1.875 * sinim * (1.0 - 2.0 * cosim - 3.0 * cosisq);
1200
+ f322 = -1.875 * sinim * (1.0 + 2.0 * cosim - 3.0 * cosisq);
1201
+ f441 = 35.0 * sini2 * f220;
1202
+ f442 = 39.3750 * sini2 * sini2;
1203
+
1204
+ f522 = 9.84375 * sinim * (sini2 * (1.0 - 2.0 * cosim - 5.0 * cosisq) + 0.33333333 * (-2.0 + 4.0 * cosim + 6.0 * cosisq));
1205
+ f523 = sinim * (4.92187512 * sini2 * (-2.0 - 4.0 * cosim + 10.0 * cosisq) + 6.56250012 * (1.0 + 2.0 * cosim - 3.0 * cosisq));
1206
+ f542 = 29.53125 * sinim * (2.0 - 8.0 * cosim + cosisq * (-12.0 + 8.0 * cosim + 10.0 * cosisq));
1207
+ f543 = 29.53125 * sinim * (-2.0 - 8.0 * cosim + cosisq * (12.0 + 8.0 * cosim - 10.0 * cosisq));
1208
+
1209
+ xno2 = nm * nm;
1210
+ ainv2 = aonv * aonv;
1211
+ temp1 = 3.0 * xno2 * ainv2;
1212
+ temp = temp1 * root22;
1213
+ d2201 = temp * f220 * g201;
1214
+ d2211 = temp * f221 * g211;
1215
+ temp1 *= aonv;
1216
+ temp = temp1 * root32;
1217
+ d3210 = temp * f321 * g310;
1218
+ d3222 = temp * f322 * g322;
1219
+ temp1 *= aonv;
1220
+ temp = 2.0 * temp1 * root44;
1221
+ d4410 = temp * f441 * g410;
1222
+ d4422 = temp * f442 * g422;
1223
+ temp1 *= aonv;
1224
+ temp = temp1 * root52;
1225
+ d5220 = temp * f522 * g520;
1226
+ d5232 = temp * f523 * g532;
1227
+ temp = 2.0 * temp1 * root54;
1228
+ d5421 = temp * f542 * g521;
1229
+ d5433 = temp * f543 * g533;
1230
+ xlamo = (mo + nodeo + nodeo - (theta + theta)) % twoPi;
1231
+ xfact = mdot + dmdt + 2.0 * (nodedot + dnodt - rptim) - no;
1232
+ em = emo;
1233
+ emsq = emsqo;
1234
+ }
1235
+
1236
+ // ---------------- synchronous resonance terms --------------
1237
+ if (irez === 1) {
1238
+ g200 = 1.0 + emsq * (-2.5 + 0.8125 * emsq);
1239
+ g310 = 1.0 + 2.0 * emsq;
1240
+ g300 = 1.0 + emsq * (-6.0 + 6.60937 * emsq);
1241
+ f220 = 0.75 * (1.0 + cosim) * (1.0 + cosim);
1242
+ f311 = 0.9375 * sinim * sinim * (1.0 + 3.0 * cosim) - 0.75 * (1.0 + cosim);
1243
+ f330 = 1.0 + cosim;
1244
+ f330 *= 1.875 * f330 * f330;
1245
+ del1 = 3.0 * nm * nm * aonv * aonv;
1246
+ del2 = 2.0 * del1 * f220 * g200 * q22;
1247
+ del3 = 3.0 * del1 * f330 * g300 * q33 * aonv;
1248
+ del1 = del1 * f311 * g310 * q31 * aonv;
1249
+ xlamo = (mo + nodeo + argpo - theta) % twoPi;
1250
+ xfact = mdot + xpidot + dmdt + domdt + dnodt - (no + rptim);
1251
+ }
1252
+
1253
+ // ------------ for sgp4, initialize the integrator ----------
1254
+ xli = xlamo;
1255
+ xni = no;
1256
+ atime = 0.0;
1257
+ nm = no + dndt;
1258
+ }
1259
+
1260
+ return {
1261
+ em: em,
1262
+ argpm: argpm,
1263
+ inclm: inclm,
1264
+ mm: mm,
1265
+ nm: nm,
1266
+ nodem: nodem,
1267
+
1268
+ irez: irez,
1269
+ atime: atime,
1270
+
1271
+ d2201: d2201,
1272
+ d2211: d2211,
1273
+ d3210: d3210,
1274
+ d3222: d3222,
1275
+ d4410: d4410,
1276
+
1277
+ d4422: d4422,
1278
+ d5220: d5220,
1279
+ d5232: d5232,
1280
+ d5421: d5421,
1281
+ d5433: d5433,
1282
+
1283
+ dedt: dedt,
1284
+ didt: didt,
1285
+ dmdt: dmdt,
1286
+ dndt: dndt,
1287
+ dnodt: dnodt,
1288
+ domdt: domdt,
1289
+
1290
+ del1: del1,
1291
+ del2: del2,
1292
+ del3: del3,
1293
+
1294
+ xfact: xfact,
1295
+ xlamo: xlamo,
1296
+ xli: xli,
1297
+ xni: xni
1298
+ };
1299
+ }
1300
+
1301
+ /* -----------------------------------------------------------------------------
1302
+ *
1303
+ * function gstime
1304
+ *
1305
+ * this function finds the greenwich sidereal time.
1306
+ *
1307
+ * author : david vallado 719-573-2600 1 mar 2001
1308
+ *
1309
+ * inputs description range / units
1310
+ * jdut1 - julian date in ut1 days from 4713 bc
1311
+ *
1312
+ * outputs :
1313
+ * gstime - greenwich sidereal time 0 to 2pi rad
1314
+ *
1315
+ * locals :
1316
+ * temp - temporary variable for doubles rad
1317
+ * tut1 - julian centuries from the
1318
+ * jan 1, 2000 12 h epoch (ut1)
1319
+ *
1320
+ * coupling :
1321
+ * none
1322
+ *
1323
+ * references :
1324
+ * vallado 2004, 191, eq 3-45
1325
+ * --------------------------------------------------------------------------- */
1326
+ function gstimeInternal(jdut1) {
1327
+ var tut1 = (jdut1 - 2451545.0) / 36525.0;
1328
+
1329
+ var temp = -6.2e-6 * tut1 * tut1 * tut1 + 0.093104 * tut1 * tut1 + (876600.0 * 3600 + 8640184.812866) * tut1 + 67310.54841; // # sec
1330
+ temp = temp * deg2rad / 240.0 % twoPi; // 360/86400 = 1/240, to deg, to rad
1331
+
1332
+ // ------------------------ check quadrants ---------------------
1333
+ if (temp < 0.0) {
1334
+ temp += twoPi;
1335
+ }
1336
+
1337
+ return temp;
1338
+ }
1339
+
1340
+ function gstime() {
1341
+ if ((arguments.length <= 0 ? undefined : arguments[0]) instanceof Date || arguments.length > 1) {
1342
+ return gstimeInternal(jday.apply(undefined, arguments));
1343
+ }
1344
+ return gstimeInternal.apply(undefined, arguments);
1345
+ }
1346
+
1347
+ /*-----------------------------------------------------------------------------
1348
+ *
1349
+ * procedure initl
1350
+ *
1351
+ * this procedure initializes the sgp4 propagator. all the initialization is
1352
+ * consolidated here instead of having multiple loops inside other routines.
1353
+ *
1354
+ * author : david vallado 719-573-2600 28 jun 2005
1355
+ *
1356
+ * inputs :
1357
+ * ecco - eccentricity 0.0 - 1.0
1358
+ * epoch - epoch time in days from jan 0, 1950. 0 hr
1359
+ * inclo - inclination of satellite
1360
+ * no - mean motion of satellite
1361
+ * satn - satellite number
1362
+ *
1363
+ * outputs :
1364
+ * ainv - 1.0 / a
1365
+ * ao - semi major axis
1366
+ * con41 -
1367
+ * con42 - 1.0 - 5.0 cos(i)
1368
+ * cosio - cosine of inclination
1369
+ * cosio2 - cosio squared
1370
+ * eccsq - eccentricity squared
1371
+ * method - flag for deep space 'd', 'n'
1372
+ * omeosq - 1.0 - ecco * ecco
1373
+ * posq - semi-parameter squared
1374
+ * rp - radius of perigee
1375
+ * rteosq - square root of (1.0 - ecco*ecco)
1376
+ * sinio - sine of inclination
1377
+ * gsto - gst at time of observation rad
1378
+ * no - mean motion of satellite
1379
+ *
1380
+ * locals :
1381
+ * ak -
1382
+ * d1 -
1383
+ * del -
1384
+ * adel -
1385
+ * po -
1386
+ *
1387
+ * coupling :
1388
+ * getgravconst
1389
+ * gstime - find greenwich sidereal time from the julian date
1390
+ *
1391
+ * references :
1392
+ * hoots, roehrich, norad spacetrack report #3 1980
1393
+ * hoots, norad spacetrack report #6 1986
1394
+ * hoots, schumacher and glover 2004
1395
+ * vallado, crawford, hujsak, kelso 2006
1396
+ ----------------------------------------------------------------------------*/
1397
+ function initl(options) {
1398
+ var ecco = options.ecco,
1399
+ epoch = options.epoch,
1400
+ inclo = options.inclo,
1401
+ opsmode = options.opsmode;
1402
+ var no = options.no;
1403
+
1404
+ // sgp4fix use old way of finding gst
1405
+ // ----------------------- earth constants ---------------------
1406
+ // sgp4fix identify constants and allow alternate values
1407
+
1408
+ // ------------- calculate auxillary epoch quantities ----------
1409
+
1410
+ var eccsq = ecco * ecco;
1411
+ var omeosq = 1.0 - eccsq;
1412
+ var rteosq = Math.sqrt(omeosq);
1413
+ var cosio = Math.cos(inclo);
1414
+ var cosio2 = cosio * cosio;
1415
+
1416
+ // ------------------ un-kozai the mean motion -----------------
1417
+ var ak = Math.pow(xke / no, x2o3);
1418
+ var d1 = 0.75 * j2 * (3.0 * cosio2 - 1.0) / (rteosq * omeosq);
1419
+ var delPrime = d1 / (ak * ak);
1420
+ var adel = ak * (1.0 - delPrime * delPrime - delPrime * (1.0 / 3.0 + 134.0 * delPrime * delPrime / 81.0));
1421
+ delPrime = d1 / (adel * adel);
1422
+ no /= 1.0 + delPrime;
1423
+
1424
+ var ao = Math.pow(xke / no, x2o3);
1425
+ var sinio = Math.sin(inclo);
1426
+ var po = ao * omeosq;
1427
+ var con42 = 1.0 - 5.0 * cosio2;
1428
+ var con41 = -con42 - cosio2 - cosio2;
1429
+ var ainv = 1.0 / ao;
1430
+ var posq = po * po;
1431
+ var rp = ao * (1.0 - ecco);
1432
+ var method = 'n';
1433
+
1434
+ // sgp4fix modern approach to finding sidereal time
1435
+ var gsto = void 0;
1436
+ if (opsmode === 'a') {
1437
+ // sgp4fix use old way of finding gst
1438
+ // count integer number of days from 0 jan 1970
1439
+ var ts70 = epoch - 7305.0;
1440
+ var ds70 = Math.floor(ts70 + 1.0e-8);
1441
+ var tfrac = ts70 - ds70;
1442
+
1443
+ // find greenwich location at epoch
1444
+ var c1 = 1.72027916940703639e-2;
1445
+ var thgr70 = 1.7321343856509374;
1446
+ var fk5r = 5.07551419432269442e-15;
1447
+ var c1p2p = c1 + twoPi;
1448
+ gsto = (thgr70 + c1 * ds70 + c1p2p * tfrac + ts70 * ts70 * fk5r) % twoPi;
1449
+ if (gsto < 0.0) {
1450
+ gsto += twoPi;
1451
+ }
1452
+ } else {
1453
+ gsto = gstime(epoch + 2433281.5);
1454
+ }
1455
+
1456
+ return {
1457
+ no: no,
1458
+
1459
+ method: method,
1460
+
1461
+ ainv: ainv,
1462
+ ao: ao,
1463
+ con41: con41,
1464
+ con42: con42,
1465
+ cosio: cosio,
1466
+
1467
+ cosio2: cosio2,
1468
+ eccsq: eccsq,
1469
+ omeosq: omeosq,
1470
+ posq: posq,
1471
+
1472
+ rp: rp,
1473
+ rteosq: rteosq,
1474
+ sinio: sinio,
1475
+ gsto: gsto
1476
+ };
1477
+ }
1478
+
1479
+ /*-----------------------------------------------------------------------------
1480
+ *
1481
+ * procedure dspace
1482
+ *
1483
+ * this procedure provides deep space contributions to mean elements for
1484
+ * perturbing third body. these effects have been averaged over one
1485
+ * revolution of the sun and moon. for earth resonance effects, the
1486
+ * effects have been averaged over no revolutions of the satellite.
1487
+ * (mean motion)
1488
+ *
1489
+ * author : david vallado 719-573-2600 28 jun 2005
1490
+ *
1491
+ * inputs :
1492
+ * d2201, d2211, d3210, d3222, d4410, d4422, d5220, d5232, d5421, d5433 -
1493
+ * dedt -
1494
+ * del1, del2, del3 -
1495
+ * didt -
1496
+ * dmdt -
1497
+ * dnodt -
1498
+ * domdt -
1499
+ * irez - flag for resonance 0-none, 1-one day, 2-half day
1500
+ * argpo - argument of perigee
1501
+ * argpdot - argument of perigee dot (rate)
1502
+ * t - time
1503
+ * tc -
1504
+ * gsto - gst
1505
+ * xfact -
1506
+ * xlamo -
1507
+ * no - mean motion
1508
+ * atime -
1509
+ * em - eccentricity
1510
+ * ft -
1511
+ * argpm - argument of perigee
1512
+ * inclm - inclination
1513
+ * xli -
1514
+ * mm - mean anomaly
1515
+ * xni - mean motion
1516
+ * nodem - right ascension of ascending node
1517
+ *
1518
+ * outputs :
1519
+ * atime -
1520
+ * em - eccentricity
1521
+ * argpm - argument of perigee
1522
+ * inclm - inclination
1523
+ * xli -
1524
+ * mm - mean anomaly
1525
+ * xni -
1526
+ * nodem - right ascension of ascending node
1527
+ * dndt -
1528
+ * nm - mean motion
1529
+ *
1530
+ * locals :
1531
+ * delt -
1532
+ * ft -
1533
+ * theta -
1534
+ * x2li -
1535
+ * x2omi -
1536
+ * xl -
1537
+ * xldot -
1538
+ * xnddt -
1539
+ * xndt -
1540
+ * xomi -
1541
+ *
1542
+ * coupling :
1543
+ * none -
1544
+ *
1545
+ * references :
1546
+ * hoots, roehrich, norad spacetrack report #3 1980
1547
+ * hoots, norad spacetrack report #6 1986
1548
+ * hoots, schumacher and glover 2004
1549
+ * vallado, crawford, hujsak, kelso 2006
1550
+ ----------------------------------------------------------------------------*/
1551
+ function dspace(options) {
1552
+ var irez = options.irez,
1553
+ d2201 = options.d2201,
1554
+ d2211 = options.d2211,
1555
+ d3210 = options.d3210,
1556
+ d3222 = options.d3222,
1557
+ d4410 = options.d4410,
1558
+ d4422 = options.d4422,
1559
+ d5220 = options.d5220,
1560
+ d5232 = options.d5232,
1561
+ d5421 = options.d5421,
1562
+ d5433 = options.d5433,
1563
+ dedt = options.dedt,
1564
+ del1 = options.del1,
1565
+ del2 = options.del2,
1566
+ del3 = options.del3,
1567
+ didt = options.didt,
1568
+ dmdt = options.dmdt,
1569
+ dnodt = options.dnodt,
1570
+ domdt = options.domdt,
1571
+ argpo = options.argpo,
1572
+ argpdot = options.argpdot,
1573
+ t = options.t,
1574
+ tc = options.tc,
1575
+ gsto = options.gsto,
1576
+ xfact = options.xfact,
1577
+ xlamo = options.xlamo,
1578
+ no = options.no;
1579
+ var atime = options.atime,
1580
+ em = options.em,
1581
+ argpm = options.argpm,
1582
+ inclm = options.inclm,
1583
+ xli = options.xli,
1584
+ mm = options.mm,
1585
+ xni = options.xni,
1586
+ nodem = options.nodem,
1587
+ nm = options.nm;
1588
+
1589
+
1590
+ var fasx2 = 0.13130908;
1591
+ var fasx4 = 2.8843198;
1592
+ var fasx6 = 0.37448087;
1593
+ var g22 = 5.7686396;
1594
+ var g32 = 0.95240898;
1595
+ var g44 = 1.8014998;
1596
+ var g52 = 1.0508330;
1597
+ var g54 = 4.4108898;
1598
+ var rptim = 4.37526908801129966e-3; // equates to 7.29211514668855e-5 rad/sec
1599
+ var stepp = 720.0;
1600
+ var stepn = -720.0;
1601
+ var step2 = 259200.0;
1602
+
1603
+ var delt = void 0;
1604
+ var x2li = void 0;
1605
+ var x2omi = void 0;
1606
+ var xl = void 0;
1607
+ var xldot = void 0;
1608
+ var xnddt = void 0;
1609
+ var xndt = void 0;
1610
+ var xomi = void 0;
1611
+ var dndt = 0.0;
1612
+ var ft = 0.0;
1613
+
1614
+ // ----------- calculate deep space resonance effects -----------
1615
+ var theta = (gsto + tc * rptim) % twoPi;
1616
+ em += dedt * t;
1617
+
1618
+ inclm += didt * t;
1619
+ argpm += domdt * t;
1620
+ nodem += dnodt * t;
1621
+ mm += dmdt * t;
1622
+
1623
+ // sgp4fix for negative inclinations
1624
+ // the following if statement should be commented out
1625
+ // if (inclm < 0.0)
1626
+ // {
1627
+ // inclm = -inclm;
1628
+ // argpm = argpm - pi;
1629
+ // nodem = nodem + pi;
1630
+ // }
1631
+
1632
+ /* - update resonances : numerical (euler-maclaurin) integration - */
1633
+ /* ------------------------- epoch restart ---------------------- */
1634
+ // sgp4fix for propagator problems
1635
+ // the following integration works for negative time steps and periods
1636
+ // the specific changes are unknown because the original code was so convoluted
1637
+
1638
+ // sgp4fix take out atime = 0.0 and fix for faster operation
1639
+
1640
+ if (irez !== 0) {
1641
+ // sgp4fix streamline check
1642
+ if (atime === 0.0 || t * atime <= 0.0 || Math.abs(t) < Math.abs(atime)) {
1643
+ atime = 0.0;
1644
+ xni = no;
1645
+ xli = xlamo;
1646
+ }
1647
+
1648
+ // sgp4fix move check outside loop
1649
+ if (t > 0.0) {
1650
+ delt = stepp;
1651
+ } else {
1652
+ delt = stepn;
1653
+ }
1654
+
1655
+ var iretn = 381; // added for do loop
1656
+ while (iretn === 381) {
1657
+ // ------------------- dot terms calculated -------------
1658
+ // ----------- near - synchronous resonance terms -------
1659
+ if (irez !== 2) {
1660
+ xndt = del1 * Math.sin(xli - fasx2) + del2 * Math.sin(2.0 * (xli - fasx4)) + del3 * Math.sin(3.0 * (xli - fasx6));
1661
+ xldot = xni + xfact;
1662
+ xnddt = del1 * Math.cos(xli - fasx2) + 2.0 * del2 * Math.cos(2.0 * (xli - fasx4)) + 3.0 * del3 * Math.cos(3.0 * (xli - fasx6));
1663
+ xnddt *= xldot;
1664
+ } else {
1665
+ // --------- near - half-day resonance terms --------
1666
+ xomi = argpo + argpdot * atime;
1667
+ x2omi = xomi + xomi;
1668
+ x2li = xli + xli;
1669
+ xndt = d2201 * Math.sin(x2omi + xli - g22) + d2211 * Math.sin(xli - g22) + d3210 * Math.sin(xomi + xli - g32) + d3222 * Math.sin(-xomi + xli - g32) + d4410 * Math.sin(x2omi + x2li - g44) + d4422 * Math.sin(x2li - g44) + d5220 * Math.sin(xomi + xli - g52) + d5232 * Math.sin(-xomi + xli - g52) + d5421 * Math.sin(xomi + x2li - g54) + d5433 * Math.sin(-xomi + x2li - g54);
1670
+ xldot = xni + xfact;
1671
+ xnddt = d2201 * Math.cos(x2omi + xli - g22) + d2211 * Math.cos(xli - g22) + d3210 * Math.cos(xomi + xli - g32) + d3222 * Math.cos(-xomi + xli - g32) + d5220 * Math.cos(xomi + xli - g52) + d5232 * Math.cos(-xomi + xli - g52) + 2.0 * d4410 * Math.cos(x2omi + x2li - g44) + d4422 * Math.cos(x2li - g44) + d5421 * Math.cos(xomi + x2li - g54) + d5433 * Math.cos(-xomi + x2li - g54);
1672
+ xnddt *= xldot;
1673
+ }
1674
+
1675
+ // ----------------------- integrator -------------------
1676
+ // sgp4fix move end checks to end of routine
1677
+ if (Math.abs(t - atime) >= stepp) {
1678
+ iretn = 381;
1679
+ } else {
1680
+ ft = t - atime;
1681
+ iretn = 0;
1682
+ }
1683
+
1684
+ if (iretn === 381) {
1685
+ xli += xldot * delt + xndt * step2;
1686
+ xni += xndt * delt + xnddt * step2;
1687
+ atime += delt;
1688
+ }
1689
+ }
1690
+
1691
+ nm = xni + xndt * ft + xnddt * ft * ft * 0.5;
1692
+ xl = xli + xldot * ft + xndt * ft * ft * 0.5;
1693
+ if (irez !== 1) {
1694
+ mm = xl - 2.0 * nodem + 2.0 * theta;
1695
+ dndt = nm - no;
1696
+ } else {
1697
+ mm = xl - nodem - argpm + theta;
1698
+ dndt = nm - no;
1699
+ }
1700
+ nm = no + dndt;
1701
+ }
1702
+
1703
+ return {
1704
+ atime: atime,
1705
+ em: em,
1706
+ argpm: argpm,
1707
+ inclm: inclm,
1708
+ xli: xli,
1709
+ mm: mm,
1710
+ xni: xni,
1711
+ nodem: nodem,
1712
+ dndt: dndt,
1713
+ nm: nm
1714
+ };
1715
+ }
1716
+
1717
+ var _extends = Object.assign || function (target) {
1718
+ for (var i = 1; i < arguments.length; i++) {
1719
+ var source = arguments[i];
1720
+
1721
+ for (var key in source) {
1722
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1723
+ target[key] = source[key];
1724
+ }
1725
+ }
1726
+ }
1727
+
1728
+ return target;
1729
+ };
1730
+
1731
+
1732
+
1733
+
1734
+
1735
+
1736
+
1737
+
1738
+
1739
+
1740
+
1741
+
1742
+
1743
+
1744
+
1745
+
1746
+
1747
+
1748
+
1749
+
1750
+
1751
+
1752
+
1753
+
1754
+
1755
+
1756
+
1757
+
1758
+
1759
+
1760
+
1761
+
1762
+
1763
+
1764
+
1765
+ var toConsumableArray = function (arr) {
1766
+ if (Array.isArray(arr)) {
1767
+ for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
1768
+
1769
+ return arr2;
1770
+ } else {
1771
+ return Array.from(arr);
1772
+ }
1773
+ };
1774
+
1775
+ /*----------------------------------------------------------------------------
1776
+ *
1777
+ * procedure sgp4
1778
+ *
1779
+ * this procedure is the sgp4 prediction model from space command. this is an
1780
+ * updated and combined version of sgp4 and sdp4, which were originally
1781
+ * published separately in spacetrack report //3. this version follows the
1782
+ * methodology from the aiaa paper (2006) describing the history and
1783
+ * development of the code.
1784
+ *
1785
+ * author : david vallado 719-573-2600 28 jun 2005
1786
+ *
1787
+ * inputs :
1788
+ * satrec - initialised structure from sgp4init() call.
1789
+ * tsince - time since epoch (minutes)
1790
+ *
1791
+ * outputs :
1792
+ * r - position vector km
1793
+ * v - velocity km/sec
1794
+ * return code - non-zero on error.
1795
+ * 1 - mean elements, ecc >= 1.0 or ecc < -0.001 or a < 0.95 er
1796
+ * 2 - mean motion less than 0.0
1797
+ * 3 - pert elements, ecc < 0.0 or ecc > 1.0
1798
+ * 4 - semi-latus rectum < 0.0
1799
+ * 5 - epoch elements are sub-orbital
1800
+ * 6 - satellite has decayed
1801
+ *
1802
+ * locals :
1803
+ * am -
1804
+ * axnl, aynl -
1805
+ * betal -
1806
+ * cosim , sinim , cosomm , sinomm , cnod , snod , cos2u ,
1807
+ * sin2u , coseo1 , sineo1 , cosi , sini , cosip , sinip ,
1808
+ * cosisq , cossu , sinsu , cosu , sinu
1809
+ * delm -
1810
+ * delomg -
1811
+ * dndt -
1812
+ * eccm -
1813
+ * emsq -
1814
+ * ecose -
1815
+ * el2 -
1816
+ * eo1 -
1817
+ * eccp -
1818
+ * esine -
1819
+ * argpm -
1820
+ * argpp -
1821
+ * omgadf -
1822
+ * pl -
1823
+ * r -
1824
+ * rtemsq -
1825
+ * rdotl -
1826
+ * rl -
1827
+ * rvdot -
1828
+ * rvdotl -
1829
+ * su -
1830
+ * t2 , t3 , t4 , tc
1831
+ * tem5, temp , temp1 , temp2 , tempa , tempe , templ
1832
+ * u , ux , uy , uz , vx , vy , vz
1833
+ * inclm - inclination
1834
+ * mm - mean anomaly
1835
+ * nm - mean motion
1836
+ * nodem - right asc of ascending node
1837
+ * xinc -
1838
+ * xincp -
1839
+ * xl -
1840
+ * xlm -
1841
+ * mp -
1842
+ * xmdf -
1843
+ * xmx -
1844
+ * xmy -
1845
+ * nodedf -
1846
+ * xnode -
1847
+ * nodep -
1848
+ * np -
1849
+ *
1850
+ * coupling :
1851
+ * getgravconst-
1852
+ * dpper
1853
+ * dspace
1854
+ *
1855
+ * references :
1856
+ * hoots, roehrich, norad spacetrack report //3 1980
1857
+ * hoots, norad spacetrack report //6 1986
1858
+ * hoots, schumacher and glover 2004
1859
+ * vallado, crawford, hujsak, kelso 2006
1860
+ ----------------------------------------------------------------------------*/
1861
+ function sgp4(satrec, tsince) {
1862
+ var rec = _extends({}, satrec);
1863
+
1864
+ var coseo1 = void 0;
1865
+ var sineo1 = void 0;
1866
+ var cosip = void 0;
1867
+ var sinip = void 0;
1868
+ var cosisq = void 0;
1869
+ var delm = void 0;
1870
+ var delomg = void 0;
1871
+ var eo1 = void 0;
1872
+ var argpm = void 0;
1873
+ var argpp = void 0;
1874
+ var su = void 0;
1875
+ var t3 = void 0;
1876
+ var t4 = void 0;
1877
+ var tc = void 0;
1878
+ var tem5 = void 0;
1879
+ var temp = void 0;
1880
+ var tempa = void 0;
1881
+ var tempe = void 0;
1882
+ var templ = void 0;
1883
+ var inclm = void 0;
1884
+ var mm = void 0;
1885
+ var nm = void 0;
1886
+ var nodem = void 0;
1887
+ var xincp = void 0;
1888
+ var xlm = void 0;
1889
+ var mp = void 0;
1890
+ var nodep = void 0;
1891
+
1892
+ /* ------------------ set mathematical constants --------------- */
1893
+ // sgp4fix divisor for divide by zero check on inclination
1894
+ // the old check used 1.0 + cos(pi-1.0e-9), but then compared it to
1895
+ // 1.5 e-12, so the threshold was changed to 1.5e-12 for consistency
1896
+
1897
+ var temp4 = 1.5e-12;
1898
+
1899
+ var vkmpersec = earthRadius * xke / 60.0;
1900
+
1901
+ // --------------------- clear sgp4 error flag -----------------
1902
+ rec.t = tsince;
1903
+ rec.error = 0;
1904
+
1905
+ // ------- update for secular gravity and atmospheric drag -----
1906
+ var xmdf = rec.mo + rec.mdot * rec.t;
1907
+ var argpdf = rec.argpo + rec.argpdot * rec.t;
1908
+ var nodedf = rec.nodeo + rec.nodedot * rec.t;
1909
+ argpm = argpdf;
1910
+ mm = xmdf;
1911
+ var t2 = rec.t * rec.t;
1912
+ nodem = nodedf + rec.nodecf * t2;
1913
+ tempa = 1.0 - rec.cc1 * rec.t;
1914
+ tempe = rec.bstar * rec.cc4 * rec.t;
1915
+ templ = rec.t2cof * t2;
1916
+
1917
+ if (rec.isimp !== 1) {
1918
+ delomg = rec.omgcof * rec.t;
1919
+ // sgp4fix use mutliply for speed instead of pow
1920
+ var delmtemp = 1.0 + rec.eta * Math.cos(xmdf);
1921
+ delm = rec.xmcof * (delmtemp * delmtemp * delmtemp - rec.delmo);
1922
+ temp = delomg + delm;
1923
+ mm = xmdf + temp;
1924
+ argpm = argpdf - temp;
1925
+ t3 = t2 * rec.t;
1926
+ t4 = t3 * rec.t;
1927
+ tempa = tempa - rec.d2 * t2 - rec.d3 * t3 - rec.d4 * t4;
1928
+ tempe += rec.bstar * rec.cc5 * (Math.sin(mm) - rec.sinmao);
1929
+ templ = templ + rec.t3cof * t3 + t4 * (rec.t4cof + rec.t * rec.t5cof);
1930
+ }
1931
+ nm = rec.no;
1932
+ var em = rec.ecco;
1933
+ inclm = rec.inclo;
1934
+ if (rec.method === 'd') {
1935
+ tc = rec.t;
1936
+
1937
+ var dspaceOptions = {
1938
+ irez: rec.irez,
1939
+ d2201: rec.d2201,
1940
+ d2211: rec.d2211,
1941
+ d3210: rec.d3210,
1942
+ d3222: rec.d3222,
1943
+ d4410: rec.d4410,
1944
+ d4422: rec.d4422,
1945
+ d5220: rec.d5220,
1946
+ d5232: rec.d5232,
1947
+ d5421: rec.d5421,
1948
+ d5433: rec.d5433,
1949
+ dedt: rec.dedt,
1950
+ del1: rec.del1,
1951
+ del2: rec.del2,
1952
+ del3: rec.del3,
1953
+ didt: rec.didt,
1954
+ dmdt: rec.dmdt,
1955
+ dnodt: rec.dnodt,
1956
+ domdt: rec.domdt,
1957
+ argpo: rec.argpo,
1958
+ argpdot: rec.argpdot,
1959
+ t: rec.t,
1960
+ tc: tc,
1961
+ gsto: rec.gsto,
1962
+ xfact: rec.xfact,
1963
+ xlamo: rec.xlamo,
1964
+ no: rec.no,
1965
+ atime: rec.atime,
1966
+ em: em,
1967
+ argpm: argpm,
1968
+ inclm: inclm,
1969
+ xli: rec.xli,
1970
+ mm: mm,
1971
+ xni: rec.xni,
1972
+ nodem: nodem,
1973
+ nm: nm
1974
+ };
1975
+
1976
+ var dspaceResult = dspace(dspaceOptions);
1977
+
1978
+ em = dspaceResult.em;
1979
+ argpm = dspaceResult.argpm;
1980
+ inclm = dspaceResult.inclm;
1981
+ mm = dspaceResult.mm;
1982
+ nodem = dspaceResult.nodem;
1983
+ nm = dspaceResult.nm;
1984
+ }
1985
+
1986
+ if (nm <= 0.0) {
1987
+ // printf("// error nm %f\n", nm);
1988
+ rec.error = 2;
1989
+ // sgp4fix add return
1990
+ return [false, false];
1991
+ }
1992
+
1993
+ var am = Math.pow(xke / nm, x2o3) * tempa * tempa;
1994
+ nm = xke / Math.pow(am, 1.5);
1995
+ em -= tempe;
1996
+
1997
+ // fix tolerance for error recognition
1998
+ // sgp4fix am is fixed from the previous nm check
1999
+ if (em >= 1.0 || em < -0.001) {
2000
+ // || (am < 0.95)
2001
+ // printf("// error em %f\n", em);
2002
+ rec.error = 1;
2003
+ // sgp4fix to return if there is an error in eccentricity
2004
+ return [false, false];
2005
+ }
2006
+
2007
+ // sgp4fix fix tolerance to avoid a divide by zero
2008
+ if (em < 1.0e-6) {
2009
+ em = 1.0e-6;
2010
+ }
2011
+ mm += rec.no * templ;
2012
+ xlm = mm + argpm + nodem;
2013
+
2014
+ nodem %= twoPi;
2015
+ argpm %= twoPi;
2016
+ xlm %= twoPi;
2017
+ mm = (xlm - argpm - nodem) % twoPi;
2018
+
2019
+ // ----------------- compute extra mean quantities -------------
2020
+ var sinim = Math.sin(inclm);
2021
+ var cosim = Math.cos(inclm);
2022
+
2023
+ // -------------------- add lunar-solar periodics --------------
2024
+ var ep = em;
2025
+ xincp = inclm;
2026
+ argpp = argpm;
2027
+ nodep = nodem;
2028
+ mp = mm;
2029
+ sinip = sinim;
2030
+ cosip = cosim;
2031
+ if (rec.method === 'd') {
2032
+ var dpperParameters = {
2033
+ inclo: rec.inclo,
2034
+ init: 'n',
2035
+ ep: ep,
2036
+ inclp: xincp,
2037
+ nodep: nodep,
2038
+ argpp: argpp,
2039
+ mp: mp,
2040
+ opsmode: rec.operationmod
2041
+ };
2042
+
2043
+ var dpperResult = dpper(rec, dpperParameters);
2044
+
2045
+ ep = dpperResult.ep;
2046
+ nodep = dpperResult.nodep;
2047
+ argpp = dpperResult.argpp;
2048
+ mp = dpperResult.mp;
2049
+
2050
+
2051
+ xincp = dpperResult.inclp;
2052
+
2053
+ if (xincp < 0.0) {
2054
+ xincp = -xincp;
2055
+ nodep += pi;
2056
+ argpp -= pi;
2057
+ }
2058
+ if (ep < 0.0 || ep > 1.0) {
2059
+ // printf("// error ep %f\n", ep);
2060
+ rec.error = 3;
2061
+ // sgp4fix add return
2062
+ return [false, false];
2063
+ }
2064
+ }
2065
+
2066
+ // -------------------- long period periodics ------------------
2067
+ if (rec.method === 'd') {
2068
+ sinip = Math.sin(xincp);
2069
+ cosip = Math.cos(xincp);
2070
+ rec.aycof = -0.5 * j3oj2 * sinip;
2071
+
2072
+ // sgp4fix for divide by zero for xincp = 180 deg
2073
+ if (Math.abs(cosip + 1.0) > 1.5e-12) {
2074
+ rec.xlcof = -0.25 * j3oj2 * sinip * (3.0 + 5.0 * cosip) / (1.0 + cosip);
2075
+ } else {
2076
+ rec.xlcof = -0.25 * j3oj2 * sinip * (3.0 + 5.0 * cosip) / temp4;
2077
+ }
2078
+ }
2079
+
2080
+ var axnl = ep * Math.cos(argpp);
2081
+ temp = 1.0 / (am * (1.0 - ep * ep));
2082
+ var aynl = ep * Math.sin(argpp) + temp * rec.aycof;
2083
+ var xl = mp + argpp + nodep + temp * rec.xlcof * axnl;
2084
+
2085
+ // --------------------- solve kepler's equation ---------------
2086
+ var u = (xl - nodep) % twoPi;
2087
+ eo1 = u;
2088
+ tem5 = 9999.9;
2089
+ var ktr = 1;
2090
+
2091
+ // sgp4fix for kepler iteration
2092
+ // the following iteration needs better limits on corrections
2093
+ while (Math.abs(tem5) >= 1.0e-12 && ktr <= 10) {
2094
+ sineo1 = Math.sin(eo1);
2095
+ coseo1 = Math.cos(eo1);
2096
+ tem5 = 1.0 - coseo1 * axnl - sineo1 * aynl;
2097
+ tem5 = (u - aynl * coseo1 + axnl * sineo1 - eo1) / tem5;
2098
+ if (Math.abs(tem5) >= 0.95) {
2099
+ if (tem5 > 0.0) {
2100
+ tem5 = 0.95;
2101
+ } else {
2102
+ tem5 = -0.95;
2103
+ }
2104
+ }
2105
+ eo1 += tem5;
2106
+ ktr += 1;
2107
+ }
2108
+
2109
+ // ------------- short period preliminary quantities -----------
2110
+ var ecose = axnl * coseo1 + aynl * sineo1;
2111
+ var esine = axnl * sineo1 - aynl * coseo1;
2112
+ var el2 = axnl * axnl + aynl * aynl;
2113
+ var pl = am * (1.0 - el2);
2114
+ if (pl < 0.0) {
2115
+ // printf("// error pl %f\n", pl);
2116
+ rec.error = 4;
2117
+ // sgp4fix add return
2118
+ return [false, false];
2119
+ }
2120
+
2121
+ var rl = am * (1.0 - ecose);
2122
+ var rdotl = Math.sqrt(am) * esine / rl;
2123
+ var rvdotl = Math.sqrt(pl) / rl;
2124
+ var betal = Math.sqrt(1.0 - el2);
2125
+ temp = esine / (1.0 + betal);
2126
+ var sinu = am / rl * (sineo1 - aynl - axnl * temp);
2127
+ var cosu = am / rl * (coseo1 - axnl + aynl * temp);
2128
+ su = Math.atan2(sinu, cosu);
2129
+ var sin2u = (cosu + cosu) * sinu;
2130
+ var cos2u = 1.0 - 2.0 * sinu * sinu;
2131
+ temp = 1.0 / pl;
2132
+ var temp1 = 0.5 * j2 * temp;
2133
+ var temp2 = temp1 * temp;
2134
+
2135
+ // -------------- update for short period periodics ------------
2136
+ if (rec.method === 'd') {
2137
+ cosisq = cosip * cosip;
2138
+ rec.con41 = 3.0 * cosisq - 1.0;
2139
+ rec.x1mth2 = 1.0 - cosisq;
2140
+ rec.x7thm1 = 7.0 * cosisq - 1.0;
2141
+ }
2142
+
2143
+ var mrt = rl * (1.0 - 1.5 * temp2 * betal * rec.con41) + 0.5 * temp1 * rec.x1mth2 * cos2u;
2144
+ su -= 0.25 * temp2 * rec.x7thm1 * sin2u;
2145
+ var xnode = nodep + 1.5 * temp2 * cosip * sin2u;
2146
+ var xinc = xincp + 1.5 * temp2 * cosip * sinip * cos2u;
2147
+ var mvt = rdotl - nm * temp1 * rec.x1mth2 * sin2u / xke;
2148
+ var rvdot = rvdotl + nm * temp1 * (rec.x1mth2 * cos2u + 1.5 * rec.con41) / xke;
2149
+
2150
+ // --------------------- orientation vectors -------------------
2151
+ var sinsu = Math.sin(su);
2152
+ var cossu = Math.cos(su);
2153
+ var snod = Math.sin(xnode);
2154
+ var cnod = Math.cos(xnode);
2155
+ var sini = Math.sin(xinc);
2156
+ var cosi = Math.cos(xinc);
2157
+ var xmx = -snod * cosi;
2158
+ var xmy = cnod * cosi;
2159
+ var ux = xmx * sinsu + cnod * cossu;
2160
+ var uy = xmy * sinsu + snod * cossu;
2161
+ var uz = sini * sinsu;
2162
+ var vx = xmx * cossu - cnod * sinsu;
2163
+ var vy = xmy * cossu - snod * sinsu;
2164
+ var vz = sini * cossu;
2165
+
2166
+ // --------- position and velocity (in km and km/sec) ----------
2167
+ var r = {
2168
+ x: mrt * ux * earthRadius,
2169
+ y: mrt * uy * earthRadius,
2170
+ z: mrt * uz * earthRadius
2171
+ };
2172
+ var v = {
2173
+ x: (mvt * ux + rvdot * vx) * vkmpersec,
2174
+ y: (mvt * uy + rvdot * vy) * vkmpersec,
2175
+ z: (mvt * uz + rvdot * vz) * vkmpersec
2176
+ };
2177
+
2178
+ // sgp4fix for decaying satellites
2179
+ if (mrt < 1.0) {
2180
+ // printf("// decay condition %11.6f \n",mrt);
2181
+ rec.error = 6;
2182
+ return {
2183
+ position: false,
2184
+ velocity: false,
2185
+ satrec: rec
2186
+ };
2187
+ }
2188
+
2189
+ return {
2190
+ position: r,
2191
+ velocity: v,
2192
+ satrec: rec
2193
+ };
2194
+ }
2195
+
2196
+ /*-----------------------------------------------------------------------------
2197
+ *
2198
+ * procedure sgp4init
2199
+ *
2200
+ * this procedure initializes variables for sgp4.
2201
+ *
2202
+ * author : david vallado 719-573-2600 28 jun 2005
2203
+ * author : david vallado 719-573-2600 28 jun 2005
2204
+ *
2205
+ * inputs :
2206
+ * opsmode - mode of operation afspc or improved 'a', 'i'
2207
+ * satn - satellite number
2208
+ * bstar - sgp4 type drag coefficient kg/m2er
2209
+ * ecco - eccentricity
2210
+ * epoch - epoch time in days from jan 0, 1950. 0 hr
2211
+ * argpo - argument of perigee (output if ds)
2212
+ * inclo - inclination
2213
+ * mo - mean anomaly (output if ds)
2214
+ * no - mean motion
2215
+ * nodeo - right ascension of ascending node
2216
+ *
2217
+ * outputs :
2218
+ * rec - common values for subsequent calls
2219
+ * return code - non-zero on error.
2220
+ * 1 - mean elements, ecc >= 1.0 or ecc < -0.001 or a < 0.95 er
2221
+ * 2 - mean motion less than 0.0
2222
+ * 3 - pert elements, ecc < 0.0 or ecc > 1.0
2223
+ * 4 - semi-latus rectum < 0.0
2224
+ * 5 - epoch elements are sub-orbital
2225
+ * 6 - satellite has decayed
2226
+ *
2227
+ * locals :
2228
+ * cnodm , snodm , cosim , sinim , cosomm , sinomm
2229
+ * cc1sq , cc2 , cc3
2230
+ * coef , coef1
2231
+ * cosio4 -
2232
+ * day -
2233
+ * dndt -
2234
+ * em - eccentricity
2235
+ * emsq - eccentricity squared
2236
+ * eeta -
2237
+ * etasq -
2238
+ * gam -
2239
+ * argpm - argument of perigee
2240
+ * nodem -
2241
+ * inclm - inclination
2242
+ * mm - mean anomaly
2243
+ * nm - mean motion
2244
+ * perige - perigee
2245
+ * pinvsq -
2246
+ * psisq -
2247
+ * qzms24 -
2248
+ * rtemsq -
2249
+ * s1, s2, s3, s4, s5, s6, s7 -
2250
+ * sfour -
2251
+ * ss1, ss2, ss3, ss4, ss5, ss6, ss7 -
2252
+ * sz1, sz2, sz3
2253
+ * sz11, sz12, sz13, sz21, sz22, sz23, sz31, sz32, sz33 -
2254
+ * tc -
2255
+ * temp -
2256
+ * temp1, temp2, temp3 -
2257
+ * tsi -
2258
+ * xpidot -
2259
+ * xhdot1 -
2260
+ * z1, z2, z3 -
2261
+ * z11, z12, z13, z21, z22, z23, z31, z32, z33 -
2262
+ *
2263
+ * coupling :
2264
+ * getgravconst-
2265
+ * initl -
2266
+ * dscom -
2267
+ * dpper -
2268
+ * dsinit -
2269
+ * sgp4 -
2270
+ *
2271
+ * references :
2272
+ * hoots, roehrich, norad spacetrack report #3 1980
2273
+ * hoots, norad spacetrack report #6 1986
2274
+ * hoots, schumacher and glover 2004
2275
+ * vallado, crawford, hujsak, kelso 2006
2276
+ ----------------------------------------------------------------------------*/
2277
+ function sgp4init(satrec, options) {
2278
+ var rec = _extends({}, satrec);
2279
+
2280
+ var opsmode = options.opsmode,
2281
+ satn = options.satn,
2282
+ epoch = options.epoch,
2283
+ xbstar = options.xbstar,
2284
+ xecco = options.xecco,
2285
+ xargpo = options.xargpo,
2286
+ xinclo = options.xinclo,
2287
+ xmo = options.xmo,
2288
+ xno = options.xno,
2289
+ xnodeo = options.xnodeo;
2290
+
2291
+
2292
+ var cosim = void 0;
2293
+ var sinim = void 0;
2294
+ var cc1sq = void 0;
2295
+ var cc2 = void 0;
2296
+ var cc3 = void 0;
2297
+ var coef = void 0;
2298
+ var coef1 = void 0;
2299
+ var cosio4 = void 0;
2300
+ var em = void 0;
2301
+ var emsq = void 0;
2302
+ var eeta = void 0;
2303
+ var etasq = void 0;
2304
+ var argpm = void 0;
2305
+ var nodem = void 0;
2306
+ var inclm = void 0;
2307
+ var mm = void 0;
2308
+ var nm = void 0;
2309
+ var perige = void 0;
2310
+ var pinvsq = void 0;
2311
+ var psisq = void 0;
2312
+ var qzms24 = void 0;
2313
+ var s1 = void 0;
2314
+ var s2 = void 0;
2315
+ var s3 = void 0;
2316
+ var s4 = void 0;
2317
+ var s5 = void 0;
2318
+ var sfour = void 0;
2319
+ var ss1 = void 0;
2320
+ var ss2 = void 0;
2321
+ var ss3 = void 0;
2322
+ var ss4 = void 0;
2323
+ var ss5 = void 0;
2324
+ var sz1 = void 0;
2325
+ var sz3 = void 0;
2326
+ var sz11 = void 0;
2327
+ var sz13 = void 0;
2328
+ var sz21 = void 0;
2329
+ var sz23 = void 0;
2330
+ var sz31 = void 0;
2331
+ var sz33 = void 0;
2332
+ var tc = void 0;
2333
+ var temp = void 0;
2334
+ var temp1 = void 0;
2335
+ var temp2 = void 0;
2336
+ var temp3 = void 0;
2337
+ var tsi = void 0;
2338
+ var xpidot = void 0;
2339
+ var xhdot1 = void 0;
2340
+ var z1 = void 0;
2341
+ var z3 = void 0;
2342
+ var z11 = void 0;
2343
+ var z13 = void 0;
2344
+ var z21 = void 0;
2345
+ var z23 = void 0;
2346
+ var z31 = void 0;
2347
+ var z33 = void 0;
2348
+
2349
+ /* ------------------------ initialization --------------------- */
2350
+ // sgp4fix divisor for divide by zero check on inclination
2351
+ // the old check used 1.0 + Math.cos(pi-1.0e-9), but then compared it to
2352
+ // 1.5 e-12, so the threshold was changed to 1.5e-12 for consistency
2353
+ var temp4 = 1.5e-12;
2354
+
2355
+ // ----------- set all near earth variables to zero ------------
2356
+ rec.isimp = 0;rec.method = 'n';rec.aycof = 0.0;
2357
+ rec.con41 = 0.0;rec.cc1 = 0.0;rec.cc4 = 0.0;
2358
+ rec.cc5 = 0.0;rec.d2 = 0.0;rec.d3 = 0.0;
2359
+ rec.d4 = 0.0;rec.delmo = 0.0;rec.eta = 0.0;
2360
+ rec.argpdot = 0.0;rec.omgcof = 0.0;rec.sinmao = 0.0;
2361
+ rec.t = 0.0;rec.t2cof = 0.0;rec.t3cof = 0.0;
2362
+ rec.t4cof = 0.0;rec.t5cof = 0.0;rec.x1mth2 = 0.0;
2363
+ rec.x7thm1 = 0.0;rec.mdot = 0.0;rec.nodedot = 0.0;
2364
+ rec.xlcof = 0.0;rec.xmcof = 0.0;rec.nodecf = 0.0;
2365
+
2366
+ // ----------- set all deep space variables to zero ------------
2367
+ rec.irez = 0;rec.d2201 = 0.0;rec.d2211 = 0.0;
2368
+ rec.d3210 = 0.0;rec.d3222 = 0.0;rec.d4410 = 0.0;
2369
+ rec.d4422 = 0.0;rec.d5220 = 0.0;rec.d5232 = 0.0;
2370
+ rec.d5421 = 0.0;rec.d5433 = 0.0;rec.dedt = 0.0;
2371
+ rec.del1 = 0.0;rec.del2 = 0.0;rec.del3 = 0.0;
2372
+ rec.didt = 0.0;rec.dmdt = 0.0;rec.dnodt = 0.0;
2373
+ rec.domdt = 0.0;rec.e3 = 0.0;rec.ee2 = 0.0;
2374
+ rec.peo = 0.0;rec.pgho = 0.0;rec.pho = 0.0;
2375
+ rec.pinco = 0.0;rec.plo = 0.0;rec.se2 = 0.0;
2376
+ rec.se3 = 0.0;rec.sgh2 = 0.0;rec.sgh3 = 0.0;
2377
+ rec.sgh4 = 0.0;rec.sh2 = 0.0;rec.sh3 = 0.0;
2378
+ rec.si2 = 0.0;rec.si3 = 0.0;rec.sl2 = 0.0;
2379
+ rec.sl3 = 0.0;rec.sl4 = 0.0;rec.gsto = 0.0;
2380
+ rec.xfact = 0.0;rec.xgh2 = 0.0;rec.xgh3 = 0.0;
2381
+ rec.xgh4 = 0.0;rec.xh2 = 0.0;rec.xh3 = 0.0;
2382
+ rec.xi2 = 0.0;rec.xi3 = 0.0;rec.xl2 = 0.0;
2383
+ rec.xl3 = 0.0;rec.xl4 = 0.0;rec.xlamo = 0.0;
2384
+ rec.zmol = 0.0;rec.zmos = 0.0;rec.atime = 0.0;
2385
+ rec.xli = 0.0;rec.xni = 0.0;
2386
+
2387
+ // sgp4fix - note the following variables are also passed directly via rec.
2388
+ // it is possible to streamline the sgp4init call by deleting the "x"
2389
+ // variables, but the user would need to set the rec.* values first. we
2390
+ // include the additional assignments in case twoline2rv is not used.
2391
+
2392
+ rec.bstar = xbstar;
2393
+ rec.ecco = xecco;
2394
+ rec.argpo = xargpo;
2395
+ rec.inclo = xinclo;
2396
+ rec.mo = xmo;
2397
+ rec.no = xno;
2398
+ rec.nodeo = xnodeo;
2399
+
2400
+ // sgp4fix add opsmode
2401
+ rec.operationmode = opsmode;
2402
+
2403
+ // ------------------------ earth constants -----------------------
2404
+ // sgp4fix identify constants and allow alternate values
2405
+
2406
+ var ss = 78.0 / earthRadius + 1.0;
2407
+ // sgp4fix use multiply for speed instead of pow
2408
+ var qzms2ttemp = (120.0 - 78.0) / earthRadius;
2409
+ var qzms2t = qzms2ttemp * qzms2ttemp * qzms2ttemp * qzms2ttemp;
2410
+
2411
+ rec.init = 'y';
2412
+ rec.t = 0.0;
2413
+
2414
+ var initlOptions = {
2415
+ satn: satn,
2416
+ ecco: rec.ecco,
2417
+
2418
+ epoch: epoch,
2419
+ inclo: rec.inclo,
2420
+ no: rec.no,
2421
+
2422
+ method: rec.method,
2423
+ opsmode: rec.operationmode
2424
+ };
2425
+
2426
+ var initlResult = initl(initlOptions);
2427
+
2428
+ var ao = initlResult.ao,
2429
+ con42 = initlResult.con42,
2430
+ cosio = initlResult.cosio,
2431
+ cosio2 = initlResult.cosio2,
2432
+ eccsq = initlResult.eccsq,
2433
+ omeosq = initlResult.omeosq,
2434
+ posq = initlResult.posq,
2435
+ rp = initlResult.rp,
2436
+ rteosq = initlResult.rteosq,
2437
+ sinio = initlResult.sinio;
2438
+
2439
+
2440
+ rec.no = initlResult.no;
2441
+ rec.con41 = initlResult.con41;
2442
+ rec.gsto = initlResult.gsto;
2443
+ rec.error = 0;
2444
+
2445
+ // sgp4fix remove this check as it is unnecessary
2446
+ // the mrt check in sgp4 handles decaying satellite cases even if the starting
2447
+ // condition is below the surface of te earth
2448
+ // if (rp < 1.0)
2449
+ // {
2450
+ // printf("// *** satn%d epoch elts sub-orbital ***\n", satn);
2451
+ // rec.error = 5;
2452
+ // }
2453
+
2454
+ if (omeosq >= 0.0 || rec.no >= 0.0) {
2455
+ rec.isimp = 0;
2456
+ if ((rp < 220.0 / earthRadius) + 1.0) {
2457
+ rec.isimp = 1;
2458
+ }
2459
+ sfour = ss;
2460
+ qzms24 = qzms2t;
2461
+ perige = (rp - 1.0) * earthRadius;
2462
+
2463
+ // - for perigees below 156 km, s and qoms2t are altered -
2464
+ if (perige < 156.0) {
2465
+ sfour = perige - 78.0;
2466
+ if (perige < 98.0) {
2467
+ sfour = 20.0;
2468
+ }
2469
+
2470
+ // sgp4fix use multiply for speed instead of pow
2471
+ var qzms24temp = (120.0 - sfour) / earthRadius;
2472
+ qzms24 = qzms24temp * qzms24temp * qzms24temp * qzms24temp;
2473
+ sfour = sfour / earthRadius + 1.0;
2474
+ }
2475
+ pinvsq = 1.0 / posq;
2476
+
2477
+ tsi = 1.0 / (ao - sfour);
2478
+ rec.eta = ao * rec.ecco * tsi;
2479
+ etasq = rec.eta * rec.eta;
2480
+ eeta = rec.ecco * rec.eta;
2481
+ psisq = Math.abs(1.0 - etasq);
2482
+ coef = qzms24 * Math.pow(tsi, 4.0);
2483
+ coef1 = coef / Math.pow(psisq, 3.5);
2484
+ cc2 = coef1 * rec.no * (ao * (1.0 + 1.5 * etasq + eeta * (4.0 + etasq)) + 0.375 * j2 * tsi / psisq * rec.con41 * (8.0 + 3.0 * etasq * (8.0 + etasq)));
2485
+ rec.cc1 = rec.bstar * cc2;
2486
+ cc3 = 0.0;
2487
+ if (rec.ecco > 1.0e-4) {
2488
+ cc3 = -2.0 * coef * tsi * j3oj2 * rec.no * sinio / rec.ecco;
2489
+ }
2490
+ rec.x1mth2 = 1.0 - cosio2;
2491
+ rec.cc4 = 2.0 * rec.no * coef1 * ao * omeosq * (rec.eta * (2.0 + 0.5 * etasq) + rec.ecco * (0.5 + 2.0 * etasq) - j2 * tsi / (ao * psisq) * (-3.0 * rec.con41 * (1.0 - 2.0 * eeta + etasq * (1.5 - 0.5 * eeta)) + 0.75 * rec.x1mth2 * (2.0 * etasq - eeta * (1.0 + etasq)) * Math.cos(2.0 * rec.argpo)));
2492
+ rec.cc5 = 2.0 * coef1 * ao * omeosq * (1.0 + 2.75 * (etasq + eeta) + eeta * etasq);
2493
+ cosio4 = cosio2 * cosio2;
2494
+ temp1 = 1.5 * j2 * pinvsq * rec.no;
2495
+ temp2 = 0.5 * temp1 * j2 * pinvsq;
2496
+ temp3 = -0.46875 * j4 * pinvsq * pinvsq * rec.no;
2497
+ rec.mdot = rec.no + 0.5 * temp1 * rteosq * rec.con41 + 0.0625 * temp2 * rteosq * (13.0 - 78.0 * cosio2 + 137.0 * cosio4);
2498
+ rec.argpdot = -0.5 * temp1 * con42 + 0.0625 * temp2 * (7.0 - 114.0 * cosio2 + 395.0 * cosio4) + temp3 * (3.0 - 36.0 * cosio2 + 49.0 * cosio4);
2499
+ xhdot1 = -temp1 * cosio;
2500
+ rec.nodedot = xhdot1 + (0.5 * temp2 * (4.0 - 19.0 * cosio2) + 2.0 * temp3 * (3.0 - 7.0 * cosio2)) * cosio;
2501
+ xpidot = rec.argpdot + rec.nodedot;
2502
+ rec.omgcof = rec.bstar * cc3 * Math.cos(rec.argpo);
2503
+ rec.xmcof = 0.0;
2504
+ if (rec.ecco > 1.0e-4) {
2505
+ rec.xmcof = -x2o3 * coef * rec.bstar / eeta;
2506
+ }
2507
+ rec.nodecf = 3.5 * omeosq * xhdot1 * rec.cc1;
2508
+ rec.t2cof = 1.5 * rec.cc1;
2509
+
2510
+ // sgp4fix for divide by zero with xinco = 180 deg
2511
+ if (Math.abs(cosio + 1.0) > 1.5e-12) {
2512
+ rec.xlcof = -0.25 * j3oj2 * sinio * (3.0 + 5.0 * cosio) / (1.0 + cosio);
2513
+ } else {
2514
+ rec.xlcof = -0.25 * j3oj2 * sinio * (3.0 + 5.0 * cosio) / temp4;
2515
+ }
2516
+ rec.aycof = -0.5 * j3oj2 * sinio;
2517
+
2518
+ // sgp4fix use multiply for speed instead of pow
2519
+ var delmotemp = 1.0 + rec.eta * Math.cos(rec.mo);
2520
+ rec.delmo = delmotemp * delmotemp * delmotemp;
2521
+ rec.sinmao = Math.sin(rec.mo);
2522
+ rec.x7thm1 = 7.0 * cosio2 - 1.0;
2523
+
2524
+ // --------------- deep space initialization -------------
2525
+ if (2 * pi / rec.no >= 225.0) {
2526
+ rec.method = 'd';
2527
+ rec.isimp = 1;
2528
+ tc = 0.0;
2529
+ inclm = rec.inclo;
2530
+
2531
+ var dscomOptions = {
2532
+ epoch: epoch,
2533
+ ep: rec.ecco,
2534
+ argpp: rec.argpo,
2535
+ tc: tc,
2536
+ inclp: rec.inclo,
2537
+ nodep: rec.nodeo,
2538
+
2539
+ np: rec.no,
2540
+
2541
+ e3: rec.e3,
2542
+ ee2: rec.ee2,
2543
+
2544
+ peo: rec.peo,
2545
+ pgho: rec.pgho,
2546
+ pho: rec.pho,
2547
+ pinco: rec.pinco,
2548
+
2549
+ plo: rec.plo,
2550
+ se2: rec.se2,
2551
+ se3: rec.se3,
2552
+
2553
+ sgh2: rec.sgh2,
2554
+ sgh3: rec.sgh3,
2555
+ sgh4: rec.sgh4,
2556
+
2557
+ sh2: rec.sh2,
2558
+ sh3: rec.sh3,
2559
+ si2: rec.si2,
2560
+ si3: rec.si3,
2561
+
2562
+ sl2: rec.sl2,
2563
+ sl3: rec.sl3,
2564
+ sl4: rec.sl4,
2565
+
2566
+ xgh2: rec.xgh2,
2567
+ xgh3: rec.xgh3,
2568
+ xgh4: rec.xgh4,
2569
+ xh2: rec.xh2,
2570
+
2571
+ xh3: rec.xh3,
2572
+ xi2: rec.xi2,
2573
+ xi3: rec.xi3,
2574
+ xl2: rec.xl2,
2575
+
2576
+ xl3: rec.xl3,
2577
+ xl4: rec.xl4,
2578
+
2579
+ zmol: rec.zmol,
2580
+ zmos: rec.zmos
2581
+ };
2582
+
2583
+ var dscomResult = dscom(dscomOptions);
2584
+
2585
+ rec.e3 = dscomResult.e3;
2586
+ rec.ee2 = dscomResult.ee2;
2587
+
2588
+ rec.peo = dscomResult.peo;
2589
+ rec.pgho = dscomResult.pgho;
2590
+ rec.pho = dscomResult.pho;
2591
+
2592
+ rec.pinco = dscomResult.pinco;
2593
+ rec.plo = dscomResult.plo;
2594
+ rec.se2 = dscomResult.se2;
2595
+ rec.se3 = dscomResult.se3;
2596
+
2597
+ rec.sgh2 = dscomResult.sgh2;
2598
+ rec.sgh3 = dscomResult.sgh3;
2599
+ rec.sgh4 = dscomResult.sgh4;
2600
+ rec.sh2 = dscomResult.sh2;
2601
+ rec.sh3 = dscomResult.sh3;
2602
+
2603
+ rec.si2 = dscomResult.si2;
2604
+ rec.si3 = dscomResult.si3;
2605
+ rec.sl2 = dscomResult.sl2;
2606
+ rec.sl3 = dscomResult.sl3;
2607
+ rec.sl4 = dscomResult.sl4;
2608
+
2609
+ sinim = dscomResult.sinim;
2610
+ cosim = dscomResult.cosim;
2611
+ em = dscomResult.em;
2612
+ emsq = dscomResult.emsq;
2613
+ s1 = dscomResult.s1;
2614
+ s2 = dscomResult.s2;
2615
+ s3 = dscomResult.s3;
2616
+ s4 = dscomResult.s4;
2617
+ s5 = dscomResult.s5;
2618
+ ss1 = dscomResult.ss1;
2619
+ ss2 = dscomResult.ss2;
2620
+ ss3 = dscomResult.ss3;
2621
+ ss4 = dscomResult.ss4;
2622
+ ss5 = dscomResult.ss5;
2623
+ sz1 = dscomResult.sz1;
2624
+ sz3 = dscomResult.sz3;
2625
+ sz11 = dscomResult.sz11;
2626
+ sz13 = dscomResult.sz13;
2627
+ sz21 = dscomResult.sz21;
2628
+ sz23 = dscomResult.sz23;
2629
+ sz31 = dscomResult.sz31;
2630
+ sz33 = dscomResult.sz33;
2631
+
2632
+
2633
+ rec.xgh2 = dscomResult.xgh2;
2634
+ rec.xgh3 = dscomResult.xgh3;
2635
+ rec.xgh4 = dscomResult.xgh4;
2636
+ rec.xh2 = dscomResult.xh2;
2637
+ rec.xh3 = dscomResult.xh3;
2638
+ rec.xi2 = dscomResult.xi2;
2639
+ rec.xi3 = dscomResult.xi3;
2640
+ rec.xl2 = dscomResult.xl2;
2641
+ rec.xl3 = dscomResult.xl3;
2642
+ rec.xl4 = dscomResult.xl4;
2643
+ rec.zmol = dscomResult.zmol;
2644
+ rec.zmos = dscomResult.zmos;
2645
+
2646
+ nm = dscomResult.nm;
2647
+ z1 = dscomResult.z1;
2648
+ z3 = dscomResult.z3;
2649
+ z11 = dscomResult.z11;
2650
+ z13 = dscomResult.z13;
2651
+ z21 = dscomResult.z21;
2652
+ z23 = dscomResult.z23;
2653
+ z31 = dscomResult.z31;
2654
+ z33 = dscomResult.z33;
2655
+
2656
+
2657
+ var dpperOptions = {
2658
+ inclo: inclm,
2659
+ init: rec.init,
2660
+ ep: rec.ecco,
2661
+ inclp: rec.inclo,
2662
+ nodep: rec.nodeo,
2663
+ argpp: rec.argpo,
2664
+ mp: rec.mo,
2665
+ opsmode: rec.operationmode
2666
+ };
2667
+
2668
+ var dpperResult = dpper(rec, dpperOptions);
2669
+
2670
+ rec.ecco = dpperResult.ep;
2671
+ rec.inclo = dpperResult.inclp;
2672
+ rec.nodeo = dpperResult.nodep;
2673
+ rec.argpo = dpperResult.argpp;
2674
+ rec.mo = dpperResult.mp;
2675
+
2676
+ argpm = 0.0;
2677
+ nodem = 0.0;
2678
+ mm = 0.0;
2679
+
2680
+ var dsinitOptions = {
2681
+ cosim: cosim,
2682
+ emsq: emsq,
2683
+ argpo: rec.argpo,
2684
+ s1: s1,
2685
+ s2: s2,
2686
+ s3: s3,
2687
+ s4: s4,
2688
+ s5: s5,
2689
+ sinim: sinim,
2690
+ ss1: ss1,
2691
+ ss2: ss2,
2692
+ ss3: ss3,
2693
+ ss4: ss4,
2694
+ ss5: ss5,
2695
+ sz1: sz1,
2696
+ sz3: sz3,
2697
+ sz11: sz11,
2698
+ sz13: sz13,
2699
+ sz21: sz21,
2700
+ sz23: sz23,
2701
+ sz31: sz31,
2702
+ sz33: sz33,
2703
+ t: rec.t,
2704
+ tc: tc,
2705
+ gsto: rec.gsto,
2706
+ mo: rec.mo,
2707
+ mdot: rec.mdot,
2708
+ no: rec.no,
2709
+ nodeo: rec.nodeo,
2710
+ nodedot: rec.nodedot,
2711
+ xpidot: xpidot,
2712
+ z1: z1,
2713
+ z3: z3,
2714
+ z11: z11,
2715
+ z13: z13,
2716
+ z21: z21,
2717
+ z23: z23,
2718
+ z31: z31,
2719
+ z33: z33,
2720
+ ecco: rec.ecco,
2721
+ eccsq: eccsq,
2722
+ em: em,
2723
+ argpm: argpm,
2724
+ inclm: inclm,
2725
+ mm: mm,
2726
+ nm: nm,
2727
+ nodem: nodem,
2728
+ irez: rec.irez,
2729
+ atime: rec.atime,
2730
+ d2201: rec.d2201,
2731
+ d2211: rec.d2211,
2732
+ d3210: rec.d3210,
2733
+ d3222: rec.d3222,
2734
+ d4410: rec.d4410,
2735
+ d4422: rec.d4422,
2736
+ d5220: rec.d5220,
2737
+ d5232: rec.d5232,
2738
+ d5421: rec.d5421,
2739
+ d5433: rec.d5433,
2740
+ dedt: rec.dedt,
2741
+ didt: rec.didt,
2742
+ dmdt: rec.dmdt,
2743
+ dnodt: rec.dnodt,
2744
+ domdt: rec.domdt,
2745
+ del1: rec.del1,
2746
+ del2: rec.del2,
2747
+ del3: rec.del3,
2748
+ xfact: rec.xfact,
2749
+ xlamo: rec.xlamo,
2750
+ xli: rec.xli,
2751
+ xni: rec.xni
2752
+ };
2753
+
2754
+ var dsinitResult = dsinit(dsinitOptions);
2755
+
2756
+ rec.irez = dsinitResult.irez;
2757
+ rec.atime = dsinitResult.atime;
2758
+ rec.d2201 = dsinitResult.d2201;
2759
+ rec.d2211 = dsinitResult.d2211;
2760
+
2761
+ rec.d3210 = dsinitResult.d3210;
2762
+ rec.d3222 = dsinitResult.d3222;
2763
+ rec.d4410 = dsinitResult.d4410;
2764
+ rec.d4422 = dsinitResult.d4422;
2765
+ rec.d5220 = dsinitResult.d5220;
2766
+
2767
+ rec.d5232 = dsinitResult.d5232;
2768
+ rec.d5421 = dsinitResult.d5421;
2769
+ rec.d5433 = dsinitResult.d5433;
2770
+ rec.dedt = dsinitResult.dedt;
2771
+ rec.didt = dsinitResult.didt;
2772
+
2773
+ rec.dmdt = dsinitResult.dmdt;
2774
+ rec.dnodt = dsinitResult.dnodt;
2775
+ rec.domdt = dsinitResult.domdt;
2776
+ rec.del1 = dsinitResult.del1;
2777
+
2778
+ rec.del2 = dsinitResult.del2;
2779
+ rec.del3 = dsinitResult.del3;
2780
+ rec.xfact = dsinitResult.xfact;
2781
+ rec.xlamo = dsinitResult.xlamo;
2782
+ rec.xli = dsinitResult.xli;
2783
+
2784
+ rec.xni = dsinitResult.xni;
2785
+ }
2786
+
2787
+ // ----------- set variables if not deep space -----------
2788
+ if (rec.isimp !== 1) {
2789
+ cc1sq = rec.cc1 * rec.cc1;
2790
+ rec.d2 = 4.0 * ao * tsi * cc1sq;
2791
+ temp = rec.d2 * tsi * rec.cc1 / 3.0;
2792
+ rec.d3 = (17.0 * ao + sfour) * temp;
2793
+ rec.d4 = 0.5 * temp * ao * tsi * (221.0 * ao + 31.0 * sfour) * rec.cc1;
2794
+ rec.t3cof = rec.d2 + 2.0 * cc1sq;
2795
+ rec.t4cof = 0.25 * (3.0 * rec.d3 + rec.cc1 * (12.0 * rec.d2 + 10.0 * cc1sq));
2796
+ rec.t5cof = 0.2 * (3.0 * rec.d4 + 12.0 * rec.cc1 * rec.d3 + 6.0 * rec.d2 * rec.d2 + 15.0 * cc1sq * (2.0 * rec.d2 + cc1sq));
2797
+ }
2798
+
2799
+ /* finally propogate to zero epoch to initialize all others. */
2800
+ // sgp4fix take out check to let satellites process until they are actually below earth surface
2801
+ // if(rec.error == 0)
2802
+ }
2803
+
2804
+ var _sgp = sgp4(rec, 0.0),
2805
+ resultRec = _sgp.satrec;
2806
+
2807
+ resultRec.init = 'n';
2808
+
2809
+ // resultRec.error contains any error codes
2810
+ return resultRec;
2811
+ }
2812
+
2813
+ /* -----------------------------------------------------------------------------
2814
+ *
2815
+ * function twoline2rv
2816
+ *
2817
+ * this function converts the two line element set character string data to
2818
+ * variables and initializes the sgp4 variables. several intermediate varaibles
2819
+ * and quantities are determined. note that the result is a structure so multiple
2820
+ * satellites can be processed simultaneously without having to reinitialize. the
2821
+ * verification mode is an important option that permits quick checks of any
2822
+ * changes to the underlying technical theory. this option works using a
2823
+ * modified tle file in which the start, stop, and delta time values are
2824
+ * included at the end of the second line of data. this only works with the
2825
+ * verification mode. the catalog mode simply propagates from -1440 to 1440 min
2826
+ * from epoch and is useful when performing entire catalog runs.
2827
+ *
2828
+ * author : david vallado 719-573-2600 1 mar 2001
2829
+ *
2830
+ * inputs :
2831
+ * longstr1 - first line of the tle
2832
+ * longstr2 - second line of the tle
2833
+ * typerun - type of run verification 'v', catalog 'c',
2834
+ * manual 'm'
2835
+ * typeinput - type of manual input mfe 'm', epoch 'e', dayofyr 'd'
2836
+ * opsmode - mode of operation afspc or improved 'a', 'i'
2837
+ * whichconst - which set of constants to use 72, 84
2838
+ *
2839
+ * outputs :
2840
+ * satrec - structure containing all the sgp4 satellite information
2841
+ *
2842
+ * coupling :
2843
+ * getgravconst-
2844
+ * days2mdhms - conversion of days to month, day, hour, minute, second
2845
+ * jday - convert day month year hour minute second into julian date
2846
+ * sgp4init - initialize the sgp4 variables
2847
+ *
2848
+ * references :
2849
+ * norad spacetrack report #3
2850
+ * vallado, crawford, hujsak, kelso 2006
2851
+ --------------------------------------------------------------------------- */
2852
+
2853
+ /**
2854
+ * Return a Satellite imported from two lines of TLE data.
2855
+ *
2856
+ * Provide the two TLE lines as strings `longstr1` and `longstr2`,
2857
+ * and select which standard set of gravitational constants you want
2858
+ * by providing `gravity_constants`:
2859
+ *
2860
+ * `sgp4.propagation.wgs72` - Standard WGS 72 model
2861
+ * `sgp4.propagation.wgs84` - More recent WGS 84 model
2862
+ * `sgp4.propagation.wgs72old` - Legacy support for old SGP4 behavior
2863
+ *
2864
+ * Normally, computations are made using letious recent improvements
2865
+ * to the algorithm. If you want to turn some of these off and go
2866
+ * back into "afspc" mode, then set `afspc_mode` to `True`.
2867
+ */
2868
+ function twoline2satrec(longstr1, longstr2) {
2869
+ var opsmode = 'i';
2870
+ var xpdotp = 1440.0 / (2.0 * pi); // 229.1831180523293;
2871
+ var year = 0;
2872
+
2873
+ var satrec = {};
2874
+ satrec.error = 0;
2875
+
2876
+ satrec.satnum = longstr1.substring(2, 7);
2877
+
2878
+ satrec.epochyr = parseInt(longstr1.substring(18, 20), 10);
2879
+ satrec.epochdays = parseFloat(longstr1.substring(20, 32));
2880
+ satrec.ndot = parseFloat(longstr1.substring(33, 43));
2881
+ satrec.nddot = parseFloat('.' + parseInt(longstr1.substring(44, 50), 10) + 'E' + longstr1.substring(50, 52));
2882
+ satrec.bstar = parseFloat(longstr1.substring(53, 54) + '.' + parseInt(longstr1.substring(54, 59), 10) + 'E' + longstr1.substring(59, 61));
2883
+
2884
+ // satrec.satnum = longstr2.substring(2, 7);
2885
+ satrec.inclo = parseFloat(longstr2.substring(8, 16));
2886
+ satrec.nodeo = parseFloat(longstr2.substring(17, 25));
2887
+ satrec.ecco = parseFloat('.' + longstr2.substring(26, 33));
2888
+ satrec.argpo = parseFloat(longstr2.substring(34, 42));
2889
+ satrec.mo = parseFloat(longstr2.substring(43, 51));
2890
+ satrec.no = parseFloat(longstr2.substring(52, 63));
2891
+
2892
+ // ---- find no, ndot, nddot ----
2893
+ satrec.no /= xpdotp; // rad/min
2894
+ // satrec.nddot= satrec.nddot * Math.pow(10.0, nexp);
2895
+ // satrec.bstar= satrec.bstar * Math.pow(10.0, ibexp);
2896
+
2897
+ // ---- convert to sgp4 units ----
2898
+ satrec.a = Math.pow(satrec.no * tumin, -2.0 / 3.0);
2899
+ satrec.ndot /= xpdotp * 1440.0; // ? * minperday
2900
+ satrec.nddot /= xpdotp * 1440.0 * 1440;
2901
+
2902
+ // ---- find standard orbital elements ----
2903
+ satrec.inclo *= deg2rad;
2904
+ satrec.nodeo *= deg2rad;
2905
+ satrec.argpo *= deg2rad;
2906
+ satrec.mo *= deg2rad;
2907
+
2908
+ satrec.alta = satrec.a * (1.0 + satrec.ecco) - 1.0;
2909
+ satrec.altp = satrec.a * (1.0 - satrec.ecco) - 1.0;
2910
+
2911
+ // ----------------------------------------------------------------
2912
+ // find sgp4epoch time of element set
2913
+ // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
2914
+ // and minutes from the epoch (time)
2915
+ // ----------------------------------------------------------------
2916
+
2917
+ // ---------------- temp fix for years from 1957-2056 -------------------
2918
+ // --------- correct fix will occur when year is 4-digit in tle ---------
2919
+
2920
+ if (satrec.epochyr < 57) {
2921
+ year = satrec.epochyr + 2000;
2922
+ } else {
2923
+ year = satrec.epochyr + 1900;
2924
+ }
2925
+
2926
+ var mdhmsResult = days2mdhms(year, satrec.epochdays);
2927
+
2928
+ var mon = mdhmsResult.mon,
2929
+ day = mdhmsResult.day,
2930
+ hr = mdhmsResult.hr,
2931
+ minute = mdhmsResult.minute,
2932
+ sec = mdhmsResult.sec;
2933
+
2934
+ satrec.jdsatepoch = jday(year, mon, day, hr, minute, sec);
2935
+
2936
+ // ---------------- initialize the orbit at sgp4epoch -------------------
2937
+ return sgp4init(satrec, {
2938
+ opsmode: opsmode,
2939
+ satn: satrec.satnum,
2940
+ epoch: satrec.jdsatepoch - 2433281.5,
2941
+ xbstar: satrec.bstar,
2942
+ xecco: satrec.ecco,
2943
+ xargpo: satrec.argpo,
2944
+ xinclo: satrec.inclo,
2945
+ xmo: satrec.mo,
2946
+ xno: satrec.no,
2947
+ xnodeo: satrec.nodeo
2948
+ });
2949
+ }
2950
+
2951
+ function propagate() {
2952
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
2953
+ args[_key] = arguments[_key];
2954
+ }
2955
+
2956
+ // Return a position and velocity vector for a given date and time.
2957
+ var satrec = args[0];
2958
+ var date = Array.prototype.slice.call(args, 1);
2959
+ var j = jday.apply(undefined, toConsumableArray(date));
2960
+ var m = (j - satrec.jdsatepoch) * minutesPerDay;
2961
+ return sgp4(satrec, m);
2962
+ }
2963
+
2964
+ function dopplerFactor(location, position, velocity) {
2965
+ var currentRange = Math.sqrt(Math.pow(position.x - location.x, 2) + Math.pow(position.y - location.y, 2) + Math.pow(position.z - location.z, 2));
2966
+
2967
+ var nextPos = {
2968
+ x: position.x + velocity.x,
2969
+ y: position.y + velocity.y,
2970
+ z: position.z + velocity.z
2971
+ };
2972
+
2973
+ var nextRange = Math.sqrt(Math.pow(nextPos.x - location.x, 2) + Math.pow(nextPos.y - location.y, 2) + Math.pow(nextPos.z - location.z, 2));
2974
+
2975
+ var rangeRate = nextRange - currentRange;
2976
+
2977
+ function sign(value) {
2978
+ return value >= 0 ? 1 : -1;
2979
+ }
2980
+
2981
+ rangeRate *= sign(rangeRate);
2982
+ var c = 299792.458; // Speed of light in km/s
2983
+ return 1 + rangeRate / c;
2984
+ }
2985
+
2986
+ function radiansToDegrees(radians) {
2987
+ return radians * rad2deg;
2988
+ }
2989
+
2990
+ function degreesLat(radians) {
2991
+ if (radians < -pi / 2 || radians > pi / 2) {
2992
+ throw new RangeError('Latitude radians must be in range [-pi/2; pi/2].');
2993
+ }
2994
+ return radiansToDegrees(radians);
2995
+ }
2996
+
2997
+ function degreesLong(radians) {
2998
+ if (radians < -pi || radians > pi) {
2999
+ throw new RangeError('Longitude radians must be in range [-pi; pi].');
3000
+ }
3001
+ return radiansToDegrees(radians);
3002
+ }
3003
+
3004
+ function geodeticToEcf(geodeticCoords) {
3005
+ var longitude = geodeticCoords.longitude,
3006
+ latitude = geodeticCoords.latitude,
3007
+ height = geodeticCoords.height;
3008
+
3009
+
3010
+ var a = 6378.137;
3011
+ var b = 6356.7523142;
3012
+ var f = (a - b) / a;
3013
+ var e2 = 2 * f - f * f;
3014
+ var normal = a / Math.sqrt(1 - e2 * (Math.sin(latitude) * Math.sin(latitude)));
3015
+
3016
+ var x = (normal + height) * Math.cos(latitude) * Math.cos(longitude);
3017
+ var y = (normal + height) * Math.cos(latitude) * Math.sin(longitude);
3018
+ var z = (normal * (1 - e2) + height) * Math.sin(latitude);
3019
+
3020
+ return {
3021
+ x: x,
3022
+ y: y,
3023
+ z: z
3024
+ };
3025
+ }
3026
+
3027
+ function eciToGeodetic(eciCoords, gmst) {
3028
+ // http://www.celestrak.com/columns/v02n03/
3029
+ var a = 6378.137;
3030
+ var b = 6356.7523142;
3031
+ var R = Math.sqrt(eciCoords.x * eciCoords.x + eciCoords.y * eciCoords.y);
3032
+ var f = (a - b) / a;
3033
+ var e2 = 2 * f - f * f;
3034
+
3035
+ var longitude = Math.atan2(eciCoords.y, eciCoords.x) - gmst;
3036
+ while (longitude < -pi) {
3037
+ longitude += twoPi;
3038
+ }
3039
+ while (longitude > pi) {
3040
+ longitude -= twoPi;
3041
+ }
3042
+
3043
+ var kmax = 20;
3044
+ var k = 0;
3045
+ var latitude = Math.atan2(eciCoords.z, Math.sqrt(eciCoords.x * eciCoords.x + eciCoords.y * eciCoords.y));
3046
+ var C = void 0;
3047
+ while (k < kmax) {
3048
+ C = 1 / Math.sqrt(1 - e2 * (Math.sin(latitude) * Math.sin(latitude)));
3049
+ latitude = Math.atan2(eciCoords.z + a * C * e2 * Math.sin(latitude), R);
3050
+ k += 1;
3051
+ }
3052
+ var height = R / Math.cos(latitude) - a * C;
3053
+ return { longitude: longitude, latitude: latitude, height: height };
3054
+ }
3055
+
3056
+ function ecfToEci(ecfCoords, gmst) {
3057
+ // ccar.colorado.edu/ASEN5070/handouts/coordsys.doc
3058
+ //
3059
+ // [X] [C -S 0][X]
3060
+ // [Y] = [S C 0][Y]
3061
+ // [Z]eci [0 0 1][Z]ecf
3062
+ //
3063
+ var X = ecfCoords.x * Math.cos(gmst) - ecfCoords.y * Math.sin(gmst);
3064
+ var Y = ecfCoords.x * Math.sin(gmst) + ecfCoords.y * Math.cos(gmst);
3065
+ var Z = ecfCoords.z;
3066
+ return { x: X, y: Y, z: Z };
3067
+ }
3068
+
3069
+ function eciToEcf(eciCoords, gmst) {
3070
+ // ccar.colorado.edu/ASEN5070/handouts/coordsys.doc
3071
+ //
3072
+ // [X] [C -S 0][X]
3073
+ // [Y] = [S C 0][Y]
3074
+ // [Z]eci [0 0 1][Z]ecf
3075
+ //
3076
+ //
3077
+ // Inverse:
3078
+ // [X] [C S 0][X]
3079
+ // [Y] = [-S C 0][Y]
3080
+ // [Z]ecf [0 0 1][Z]eci
3081
+
3082
+ var x = eciCoords.x * Math.cos(gmst) + eciCoords.y * Math.sin(gmst);
3083
+ var y = eciCoords.x * -Math.sin(gmst) + eciCoords.y * Math.cos(gmst);
3084
+ var z = eciCoords.z;
3085
+
3086
+
3087
+ return {
3088
+ x: x,
3089
+ y: y,
3090
+ z: z
3091
+ };
3092
+ }
3093
+
3094
+ function topocentric(observerCoords, satelliteCoords) {
3095
+ // http://www.celestrak.com/columns/v02n02/
3096
+ // TS Kelso's method, except I'm using ECF frame
3097
+ // and he uses ECI.
3098
+
3099
+ var longitude = observerCoords.longitude,
3100
+ latitude = observerCoords.latitude;
3101
+
3102
+
3103
+ var observerEcf = geodeticToEcf(observerCoords);
3104
+
3105
+ var rx = satelliteCoords.x - observerEcf.x;
3106
+ var ry = satelliteCoords.y - observerEcf.y;
3107
+ var rz = satelliteCoords.z - observerEcf.z;
3108
+
3109
+ var topS = Math.sin(latitude) * Math.cos(longitude) * rx + Math.sin(latitude) * Math.sin(longitude) * ry - Math.cos(latitude) * rz;
3110
+
3111
+ var topE = -Math.sin(longitude) * rx + Math.cos(longitude) * ry;
3112
+
3113
+ var topZ = Math.cos(latitude) * Math.cos(longitude) * rx + Math.cos(latitude) * Math.sin(longitude) * ry + Math.sin(latitude) * rz;
3114
+
3115
+ return { topS: topS, topE: topE, topZ: topZ };
3116
+ }
3117
+
3118
+ /**
3119
+ * @param {Object} tc
3120
+ * @param {Number} tc.topS Positive horizontal vector S due south.
3121
+ * @param {Number} tc.topE Positive horizontal vector E due east.
3122
+ * @param {Number} tc.topZ Vector Z normal to the surface of the earth (up).
3123
+ * @returns {Object}
3124
+ */
3125
+ function topocentricToLookAngles(tc) {
3126
+ var topS = tc.topS,
3127
+ topE = tc.topE,
3128
+ topZ = tc.topZ;
3129
+
3130
+ var rangeSat = Math.sqrt(topS * topS + topE * topE + topZ * topZ);
3131
+ var El = Math.asin(topZ / rangeSat);
3132
+ var Az = Math.atan2(-topE, topS) + pi;
3133
+
3134
+ return {
3135
+ azimuth: Az,
3136
+ elevation: El,
3137
+ rangeSat: rangeSat // Range in km
3138
+ };
3139
+ }
3140
+
3141
+ function ecfToLookAngles(observerCoordsEcf, satelliteCoordsEcf) {
3142
+ var topocentricCoords = topocentric(observerCoordsEcf, satelliteCoordsEcf);
3143
+ return topocentricToLookAngles(topocentricCoords);
3144
+ }
3145
+
3146
+ var gstimeFromJday = function gstimeFromJday() {
3147
+ console.warn('gstimeFromJday is deprecated, use gstime instead.'); // eslint-disable-line no-console
3148
+ return gstime.apply(undefined, arguments);
3149
+ };
3150
+
3151
+ var gstimeFromDate = function gstimeFromDate() {
3152
+ console.warn('gstimeFromDate is deprecated, use gstime instead.'); // eslint-disable-line no-console
3153
+ return gstime.apply(undefined, arguments);
3154
+ };
3155
+ var satrecmap=new Map();
3156
+ onmessage = function (param) {
3157
+
3158
+ if (param.data.type == "tle") {
3159
+ let id=param.data.id;
3160
+ var satrec = twoline2satrec(param.data.tle1, param.data.tle2);
3161
+ satrecmap.set(id,satrec);
3162
+ }
3163
+ else {
3164
+ // var r = propagate(satrec, param.data.data);
3165
+ var a=[];
3166
+ satrecmap.forEach((v,k)=>{
3167
+ var satrec=satrecmap.get(k);
3168
+ let r=propagate(satrec, param.data.data);
3169
+ a.push({id:k,data:r.position});
3170
+ })
3171
+ postMessage(a);
3172
+
3173
+ }
3174
+ }
3175
+ // export { constants, propagate, sgp4, twoline2satrec, gstime, gstimeFromJday, gstimeFromDate, jday, invjday, dopplerFactor, degreesLat, degreesLong, geodeticToEcf, eciToGeodetic, eciToEcf, ecfToEci, ecfToLookAngles };