-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsgp4.go
2656 lines (2605 loc) · 89.5 KB
/
sgp4.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Originally transpiled from
https://github.com/aholinch/sgp4/tree/master/src/c
by c2go
https://github.com/elliotchance/c2go
(version v0.25.9 Dubnium 2018-12-30).
Then edited by hand.
Original C code credit:
This file contains the sgp4 procedures for analytical propagation
of a satellite. the code was originally released in the 1980 and
1986 spacetrack papers. a detailed discussion of the theory and
history may be found in the 2006 aiaa paper by vallado, crawford,
hujsak, and kelso.
companion code for
fundamentals of astrodynamics and applications
2013
by david vallado
(w) 719-573-2600, email dvallado@agi.com, davallado@gmail.com
*/
/* ----------------------------------------------------------------
*
* sgp4unit.cpp
*
* this file contains the sgp4 procedures for analytical propagation
* of a satellite. the code was originally released in the 1980 and 1986
* spacetrack papers. a detailed discussion of the theory and history
* may be found in the 2006 aiaa paper by vallado, crawford, hujsak,
* and kelso.
*
* companion code for
* fundamentals of astrodynamics and applications
* 2013
* by david vallado
*
* (w) 719-573-2600, email dvallado@agi.com, davallado@gmail.com
*
* current :
* 7 dec 15 david vallado
* fix jd, jdfrac
* changes :
* 3 nov 14 david vallado
* update to msvs2013 c++
* 30 aug 10 david vallado
* delete unused variables in initl
* replace pow integer 2, 3 with multiplies for speed
* 3 nov 08 david vallado
* put returns in for error codes
* 29 sep 08 david vallado
* fix atime for faster operation in dspace
* add operationmode for afspc (a) or improved (i)
* performance mode
* 16 jun 08 david vallado
* update small eccentricity check
* 16 nov 07 david vallado
* misc fixes for better compliance
* 20 apr 07 david vallado
* misc fixes for constants
* 11 aug 06 david vallado
* chg lyddane choice back to strn3, constants, misc doc
* 15 dec 05 david vallado
* misc fixes
* 26 jul 05 david vallado
* fixes for paper
* note that each fix is preceded by a
* comment with "sgp4fix" and an explanation of
* what was changed
* 10 aug 04 david vallado
* 2nd printing baseline working
* 14 may 01 david vallado
* 2nd edition baseline
* 80 norad
* original baseline
* ---------------------------------------------------------------- */ //
package sgp4go
import (
"fmt"
"math"
"strconv"
"strings"
"sync"
"unsafe"
// "github.com/elliotchance/c2go/noarch"
)
// cs2s takes a C string and returns a Go string.
//
// Almost certainly something better exists.
func cs2s(bs []byte) string {
for i, b := range bs {
if b == 0 {
return string(bs[0:i])
}
}
return string(bs)
}
func sscanf(s string, format string, args ...interface{}) int {
n, _ := fmt.Sscanf(s, format, args)
return n
}
type bool_ int64
type elsetRec struct {
whichconst int64
satnum int64
epochyr int64
epochtynumrev int64
error int64
operationmode byte
init_ byte
method byte
a float64
altp float64
alta float64
epochdays float64
jdsatepoch float64
jdsatepochF float64
nddot float64
ndot float64
bstar float64
rcse float64
inclo float64
nodeo float64
ecco float64
argpo float64
mo float64
no_kozai float64
classification byte
intldesg [12]byte
ephtype int64
elnum int64
revnum int64
no_unkozai float64
am float64
em float64
im float64
Om float64
om float64
mm float64
nm float64
t float64
tumin float64
mu float64
radiusearthkm float64
xke float64
j2 float64
j3 float64
j4 float64
j3oj2 float64
dia_mm int64
period_sec float64
active byte
not_orbital byte
rcs_m2 float64
ep float64
inclp float64
nodep float64
argpp float64
mp float64
isimp int64
aycof float64
con41 float64
cc1 float64
cc4 float64
cc5 float64
d2 float64
d3 float64
d4 float64
delmo float64
eta float64
argpdot float64
omgcof float64
sinmao float64
t2cof float64
t3cof float64
t4cof float64
t5cof float64
x1mth2 float64
x7thm1 float64
mdot float64
nodedot float64
xlcof float64
xmcof float64
nodecf float64
irez int64
d2201 float64
d2211 float64
d3210 float64
d3222 float64
d4410 float64
d4422 float64
d5220 float64
d5232 float64
d5421 float64
d5433 float64
dedt float64
del1 float64
del2 float64
del3 float64
didt float64
dmdt float64
dnodt float64
domdt float64
e3 float64
ee2 float64
peo float64
pgho float64
pho float64
pinco float64
plo float64
se2 float64
se3 float64
sgh2 float64
sgh3 float64
sgh4 float64
sh2 float64
sh3 float64
si2 float64
si3 float64
sl2 float64
sl3 float64
sl4 float64
gsto float64
xfact float64
xgh2 float64
xgh3 float64
xgh4 float64
xh2 float64
xh3 float64
xi2 float64
xi3 float64
xl2 float64
xl3 float64
xl4 float64
xlamo float64
zmol float64
zmos float64
atime float64
xli float64
xni float64
snodm float64
cnodm float64
sinim float64
cosim float64
sinomm float64
cosomm float64
day float64
emsq float64
gam float64
rtemsq float64
s1 float64
s2 float64
s3 float64
s4 float64
s5 float64
s6 float64
s7 float64
ss1 float64
ss2 float64
ss3 float64
ss4 float64
ss5 float64
ss6 float64
ss7 float64
sz1 float64
sz2 float64
sz3 float64
sz11 float64
sz12 float64
sz13 float64
sz21 float64
sz22 float64
sz23 float64
sz31 float64
sz32 float64
sz33 float64
z1 float64
z2 float64
z3 float64
z11 float64
z12 float64
z13 float64
z21 float64
z22 float64
z23 float64
z31 float64
z32 float64
z33 float64
argpm float64
inclm float64
nodem float64
dndt float64
eccsq float64
ainv float64
ao float64
con42 float64
cosio float64
cosio2 float64
omeosq float64
posq float64
rp float64
rteosq float64
sinio float64
}
type TLE struct {
sync.Mutex
Rec elsetRec
line1 [70]byte
line2 [70]byte
intlid [12]byte
objectNum int64
epoch int64
ndot float64
nddot float64
bstar float64
elnum int64
incDeg float64
raanDeg float64
ecc float64
argpDeg float64
maDeg float64
n float64
revnum int64
sgp4Error int64
}
// parseLines - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:16
// parse the double
// parse the double with implied decimal
// copy the lines
// 1 2 3 4 5 6
//0123456789012345678901234567890123456789012345678901234567890123456789
//line1="1 00005U 58002B 00179.78495062 .00000023 00000-0 28098-4 0 4753";
//line2="2 00005 34.2682 348.7242 1859667 331.7664 19.3264 10.82419157413667";
// intlid
//
func parseLines(tle *TLE, line1 *byte, line2 *byte) {
(*tle).Rec.whichconst = int64(2)
strncpy64(&(*tle).line1[0], line1, int64(uint64(int64(69))))
strncpy64(&(*tle).line2[0], line2, int64(uint64(int64(69))))
*((*byte)(func() unsafe.Pointer {
tempVar := &(*tle).line1[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(69))*unsafe.Sizeof(*tempVar))
}())) = byte(int64(0))
*((*byte)(func() unsafe.Pointer {
tempVar := &(*tle).line2[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(69))*unsafe.Sizeof(*tempVar))
}())) = byte(int64(0))
strncpy64(&(*tle).intlid[0], &*((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(line1)) + (uintptr)(int64(9))*unsafe.Sizeof(*line1)))), int64(uint64(int64(8))))
(*tle).Rec.classification = *((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(line1)) + (uintptr)(int64(7))*unsafe.Sizeof(*line1))))
(*tle).objectNum = int64(gd(line1, int64(2), int64(7)))
(*tle).ndot = gdi(line1, int64(35), int64(44))
if int64(*((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(line1)) + (uintptr)(int64(33))*unsafe.Sizeof(*line1))))) == int64('-') {
(*tle).ndot *= -1
}
(*tle).nddot = gdi(line1, int64(45), int64(50))
if int64(*((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(line1)) + (uintptr)(int64(44))*unsafe.Sizeof(*line1))))) == int64('-') {
(*tle).nddot *= -1
}
(*tle).nddot *= math.Pow(10, gd(line1, int64(50), int64(52)))
(*tle).bstar = gdi(line1, int64(54), int64(59))
if int64(*((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(line1)) + (uintptr)(int64(53))*unsafe.Sizeof(*line1))))) == int64('-') {
(*tle).bstar *= -1
}
(*tle).bstar *= math.Pow(10, gd(line1, int64(59), int64(61)))
(*tle).elnum = int64(gd(line1, int64(64), int64(68)))
(*tle).incDeg = gd(line2, int64(8), int64(16))
(*tle).raanDeg = gd(line2, int64(17), int64(25))
(*tle).ecc = gdi(line2, int64(26), int64(33))
(*tle).argpDeg = gd(line2, int64(34), int64(42))
(*tle).maDeg = gd(line2, int64(43), int64(51))
(*tle).n = gd(line2, int64(52), int64(63))
(*tle).revnum = int64(gd(line2, int64(63), int64(68)))
(*tle).sgp4Error = int64(0)
(*tle).epoch = parseEpoch(&(*tle).Rec, &*((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(line1)) + (uintptr)(int64(18))*unsafe.Sizeof(*line1)))))
setValsToRec(tle, &(*tle).Rec)
}
// isLeap - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:66
func isLeap(year int64) bool_ {
if year%int64(4) != int64(0) {
return bool_((int64(0)))
}
if year%int64(100) == int64(0) {
if year%int64(400) == int64(0) {
return bool_((int64(1)))
} else {
return bool_((int64(0)))
}
}
return bool_((int64(1)))
}
// parseEpoch - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:88
// convert doy to mon, day
//
func parseEpoch(rec *elsetRec, str *byte) int64 {
var tmp []byte = make([]byte, 16, 16)
strncpy64(&tmp[0], str, int64(uint64(int64(14))))
*((*byte)(func() unsafe.Pointer {
tempVar := &tmp[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(15))*unsafe.Sizeof(*tempVar))
}())) = byte(int64(0))
var tmp2 []byte = make([]byte, 16, 16)
strncpy64(&tmp2[0], &tmp[0], int64(uint64(int64(2))))
*((*byte)(func() unsafe.Pointer {
tempVar := &tmp2[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(2))*unsafe.Sizeof(*tempVar))
}())) = byte(int64(0))
// var year int64 = noarch.Atoi64(&tmp2[0])
// noarch
year, _ := strconv.ParseInt(string(tmp2[0:2]), 10, 64)
(*rec).epochyr = year
if year > int64(56) {
year += int64(1900)
} else {
year += int64(2000)
}
strncpy64(&tmp2[0], &*((*byte)(func() unsafe.Pointer {
tempVar := &tmp[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(2))*unsafe.Sizeof(*tempVar))
}())), int64(uint64(int64(3))))
*((*byte)(func() unsafe.Pointer {
tempVar := &tmp2[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(3))*unsafe.Sizeof(*tempVar))
}())) = byte(int64(0))
// var doy int64 = noarch.Atoi64(&tmp2[0])
// noarch
doy, _ := strconv.ParseInt(string(tmp2[0:3]), 10, 64)
*&tmp2[0] = '0'
strncpy64(&*((*byte)(func() unsafe.Pointer {
tempVar := &tmp2[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(1))*unsafe.Sizeof(*tempVar))
}())), &*((*byte)(func() unsafe.Pointer {
tempVar := &tmp[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(5))*unsafe.Sizeof(*tempVar))
}())), int64(uint64(int64(9))))
*((*byte)(func() unsafe.Pointer {
tempVar := &tmp2[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(11))*unsafe.Sizeof(*tempVar))
}())) = byte(int64(0))
// var dfrac float64 = noarch.Strtod(&tmp2[0], nil)
// noarch
dfrac, _ := strconv.ParseFloat(cs2s(tmp2), 64)
// var odfrac float64 = dfrac
(*rec).epochdays = float64(doy)
(*rec).epochdays += dfrac
dfrac *= 24
var hr int64 = int64(dfrac)
dfrac = 60 * (dfrac - float64(hr))
var mn int64 = int64(dfrac)
dfrac = 60 * (dfrac - float64(mn))
var sc int64 = int64(dfrac)
dfrac = 1000 * (dfrac - float64(sc))
// var milli int64 = int64(dfrac)
var sec float64 = float64(sc) + dfrac/1000
var mon int64 = int64(0)
var day int64 = int64(0)
var days []int64 = []int64{int64(31), int64(28), int64(31), int64(30), int64(31), int64(30), int64(31), int64(31), int64(30), int64(31), int64(30), int64(31)}
if isLeap(year) == 1 {
*((*int64)(func() unsafe.Pointer {
tempVar := &days[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(1))*unsafe.Sizeof(*tempVar))
}())) = int64(29)
}
var ind int64 = int64(0)
for ind < int64(12) && doy > *((*int64)(func() unsafe.Pointer {
tempVar := &days[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(ind)*unsafe.Sizeof(*tempVar))
}())) {
doy -= *((*int64)(func() unsafe.Pointer {
tempVar := &days[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(ind)*unsafe.Sizeof(*tempVar))
}()))
ind += 1
}
mon = ind + int64(1)
day = doy
jday(year, mon, day, hr, mn, sec, &(*rec).jdsatepoch, &(*rec).jdsatepochF)
var diff float64 = (*rec).jdsatepoch - 2.4405875e+06
var diff2 float64 = 8.64e+07 * (*rec).jdsatepochF
diff *= 8.64e+07
var epoch = int64(diff2)
epoch += int64(diff)
return epoch
}
// getRVForDate - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:164
func getRVForDate(tle *TLE, millisSince1970 int64, r *float64, v *float64) {
var diff float64 = float64(millisSince1970) - float64((*tle).epoch)
diff /= 60000
getRV(tle, diff, r, v)
}
// getRV - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:171
func getRV(tle *TLE, minutesAfterEpoch float64, r *float64, v *float64) {
(*tle).Rec.error = int64(0)
sgp4(&(*tle).Rec, minutesAfterEpoch, r, v)
(*tle).sgp4Error = (*tle).Rec.error
}
// gd - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:178
func gd(str *byte, ind1 int64, ind2 int64) float64 {
var num float64 = float64(int64(0))
var tmp []byte = make([]byte, 50, 50)
var cnt int64 = ind2 - ind1
strncpy64(&tmp[0], &*((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(str)) + (uintptr)(ind1)*unsafe.Sizeof(*str)))), int64(uint64(cnt)))
*((*byte)(func() unsafe.Pointer {
tempVar := &tmp[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(cnt)*unsafe.Sizeof(*tempVar))
}())) = byte(int64(0))
// num = noarch.Strtod(&tmp[0], nil)
// noarch
num, _ = strconv.ParseFloat(strings.TrimSpace(cs2s(tmp)), 64)
return num
}
// gdi - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:190
// parse with an implied decimal place
//
func gdi(str *byte, ind1 int64, ind2 int64) float64 {
var num float64 = float64(int64(0))
var tmp []byte = make([]byte, 52, 52)
*&tmp[0] = '0'
*((*byte)(func() unsafe.Pointer {
tempVar := &tmp[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(1))*unsafe.Sizeof(*tempVar))
}())) = '.'
var cnt int64 = ind2 - ind1
strncpy64(&*((*byte)(func() unsafe.Pointer {
tempVar := &tmp[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(2))*unsafe.Sizeof(*tempVar))
}())), &*((*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(str)) + (uintptr)(ind1)*unsafe.Sizeof(*str)))), int64(uint64(cnt)))
*((*byte)(func() unsafe.Pointer {
tempVar := &tmp[0]
return unsafe.Pointer(uintptr(unsafe.Pointer(tempVar)) + (uintptr)(int64(2)+cnt)*unsafe.Sizeof(*tempVar))
}())) = byte(int64(0))
// num = noarch.Strtod(&tmp[0], nil)
// noarch
num, _ = strconv.ParseFloat(cs2s(tmp), 64)
return num
}
// setValsToRec - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:203
// 229.1831180523293
//
func setValsToRec(tle *TLE, rec *elsetRec) {
var xpdotp float64 = 1440.0 / (2.0 * 3.141592653589793)
(*rec).elnum = (*tle).elnum
(*rec).revnum = (*tle).revnum
(*rec).satnum = (*tle).objectNum
(*rec).bstar = (*tle).bstar
(*rec).inclo = (*tle).incDeg * (3.141592653589793 / 180.0)
(*rec).nodeo = (*tle).raanDeg * (3.141592653589793 / 180.0)
(*rec).argpo = (*tle).argpDeg * (3.141592653589793 / 180.0)
(*rec).mo = (*tle).maDeg * (3.141592653589793 / 180.0)
(*rec).ecco = (*tle).ecc
(*rec).no_kozai = (*tle).n / xpdotp
(*rec).ndot = (*tle).ndot / (xpdotp * 1440.0)
(*rec).nddot = (*tle).nddot / (xpdotp * 1440.0 * 1440.0)
sgp4init('a', rec)
}
// dpper - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:348
/* ----------------------------------------------------------------
*
* sgp4unit.cpp
*
* this file contains the sgp4 procedures for analytical propagation
* of a satellite. the code was originally released in the 1980 and 1986
* spacetrack papers. a detailed discussion of the theory and history
* may be found in the 2006 aiaa paper by vallado, crawford, hujsak,
* and kelso.
*
* companion code for
* fundamentals of astrodynamics and applications
* 2013
* by david vallado
*
* (w) 719-573-2600, email dvallado@agi.com, davallado@gmail.com
*
* current :
* 7 dec 15 david vallado
* fix jd, jdfrac
* changes :
* 3 nov 14 david vallado
* update to msvs2013 c++
* 30 aug 10 david vallado
* delete unused variables in initl
* replace pow integer 2, 3 with multiplies for speed
* 3 nov 08 david vallado
* put returns in for error codes
* 29 sep 08 david vallado
* fix atime for faster operation in dspace
* add operationmode for afspc (a) or improved (i)
* performance mode
* 16 jun 08 david vallado
* update small eccentricity check
* 16 nov 07 david vallado
* misc fixes for better compliance
* 20 apr 07 david vallado
* misc fixes for constants
* 11 aug 06 david vallado
* chg lyddane choice back to strn3, constants, misc doc
* 15 dec 05 david vallado
* misc fixes
* 26 jul 05 david vallado
* fixes for paper
* note that each fix is preceded by a
* comment with "sgp4fix" and an explanation of
* what was changed
* 10 aug 04 david vallado
* 2nd printing baseline working
* 14 may 01 david vallado
* 2nd edition baseline
* 80 norad
* original baseline
* ---------------------------------------------------------------- */ //
/* -----------------------------------------------------------------------------
*
* procedure dpper
*
* this procedure provides deep space long period periodic contributions
* to the mean elements. by design, these periodics are zero at epoch.
* this used to be dscom which included initialization, but it's really a
* recurring function.
*
* author : david vallado 719-573-2600 28 jun 2005
*
* inputs :
* e3 -
* ee2 -
* peo -
* pgho -
* pho -
* pinco -
* plo -
* se2 , se3 , sgh2, sgh3, sgh4, sh2, sh3, si2, si3, sl2, sl3, sl4 -
* t -
* xh2, xh3, xi2, xi3, xl2, xl3, xl4 -
* zmol -
* zmos -
* ep - eccentricity 0.0 - 1.0
* inclo - inclination - needed for lyddane modification
* nodep - right ascension of ascending node
* argpp - argument of perigee
* mp - mean anomaly
*
* outputs :
* ep - eccentricity 0.0 - 1.0
* inclp - inclination
* nodep - right ascension of ascending node
* argpp - argument of perigee
* mp - mean anomaly
*
* locals :
* alfdp -
* betdp -
* cosip , sinip , cosop , sinop ,
* dalf -
* dbet -
* dls -
* f2, f3 -
* pe -
* pgh -
* ph -
* pinc -
* pl -
* sel , ses , sghl , sghs , shl , shs , sil , sinzf , sis ,
* sll , sls
* xls -
* xnoh -
* zf -
* zm -
*
* coupling :
* none.
*
* references :
* hoots, roehrich, norad spacetrack report #3 1980
* hoots, norad spacetrack report #6 1986
* hoots, schumacher and glover 2004
* vallado, crawford, hujsak, kelso 2006
----------------------------------------------------------------------------*/ //
/* --------------------- local variables ------------------------ */ //
/* ---------------------- constants ----------------------------- */ //
/* --------------- calculate time varying periodics ----------- */ //
// be sure that the initial call has time set to zero
/* ----------------- apply periodics directly ------------ */ //
// sgp4fix for lyddane choice
// strn3 used original inclination - this is technically feasible
// gsfc used perturbed inclination - also technically feasible
// probably best to readjust the 0.2 limit value and limit discontinuity
// 0.2 rad = 11.45916 deg
// use next line for original strn3 approach and original inclination
// if (inclo >= 0.2)
// use next line for gsfc version and perturbed inclination
/* ---- apply periodics with lyddane modification ---- */ //
// sgp4fix for afspc written intrinsic functions
// nodep used without a trigonometric function ahead
// sgp4fix for afspc written intrinsic functions
// nodep used without a trigonometric function ahead
// if init == 'n'
// dpper
//
func dpper(e3 float64, ee2 float64, peo float64, pgho float64, pho float64, pinco float64, plo float64, se2 float64, se3 float64, sgh2 float64, sgh3 float64, sgh4 float64, sh2 float64, sh3 float64, si2 float64, si3 float64, sl2 float64, sl3 float64, sl4 float64, t float64, xgh2 float64, xgh3 float64, xgh4 float64, xh2 float64, xh3 float64, xi2 float64, xi3 float64, xl2 float64, xl3 float64, xl4 float64, zmol float64, zmos float64, init_ byte, rec *elsetRec, opsmode byte) {
var alfdp float64
var betdp float64
var cosip float64
var cosop float64
var dalf float64
var dbet float64
var dls float64
var f2 float64
var f3 float64
var pe float64
var pgh float64
var ph float64
var pinc float64
var pl float64
var sel float64
var ses float64
var sghl float64
var sghs float64
var shll float64
var shs float64
var sil float64
var sinip float64
var sinop float64
var sinzf float64
var sis float64
var sll float64
var sls float64
var xls float64
var xnoh float64
var zf float64
var zm float64
var zel float64
var zes float64
var znl float64
var zns float64
zns = 1.19459e-05
zes = 0.01675
znl = 0.00015835218
zel = 0.0549
zm = zmos + zns*t
if int64(init_) == int64('y') {
zm = zmos
}
zf = zm + 2*zes*math.Sin(zm)
sinzf = math.Sin(zf)
f2 = 0.5*sinzf*sinzf - 0.25
f3 = -0.5 * sinzf * math.Cos(zf)
ses = se2*f2 + se3*f3
sis = si2*f2 + si3*f3
sls = sl2*f2 + sl3*f3 + sl4*sinzf
sghs = sgh2*f2 + sgh3*f3 + sgh4*sinzf
shs = sh2*f2 + sh3*f3
zm = zmol + znl*t
if int64(init_) == int64('y') {
zm = zmol
}
zf = zm + 2*zel*math.Sin(zm)
sinzf = math.Sin(zf)
f2 = 0.5*sinzf*sinzf - 0.25
f3 = -0.5 * sinzf * math.Cos(zf)
sel = ee2*f2 + e3*f3
sil = xi2*f2 + xi3*f3
sll = xl2*f2 + xl3*f3 + xl4*sinzf
sghl = xgh2*f2 + xgh3*f3 + xgh4*sinzf
shll = xh2*f2 + xh3*f3
pe = ses + sel
pinc = sis + sil
pl = sls + sll
pgh = sghs + sghl
ph = shs + shll
if int64(init_) == int64('n') {
pe = pe - peo
pinc = pinc - pinco
pl = pl - plo
pgh = pgh - pgho
ph = ph - pho
(*rec).inclp = (*rec).inclp + pinc
(*rec).ep = (*rec).ep + pe
sinip = math.Sin((*rec).inclp)
cosip = math.Cos((*rec).inclp)
if (*rec).inclp >= 0.2 {
ph = ph / sinip
pgh = pgh - cosip*ph
(*rec).argpp = (*rec).argpp + pgh
(*rec).nodep = (*rec).nodep + ph
(*rec).mp = (*rec).mp + pl
} else {
sinop = math.Sin((*rec).nodep)
cosop = math.Cos((*rec).nodep)
alfdp = sinip * sinop
betdp = sinip * cosop
dalf = ph*cosop + pinc*cosip*sinop
dbet = -ph*sinop + pinc*cosip*cosop
alfdp = alfdp + dalf
betdp = betdp + dbet
(*rec).nodep = math.Mod((*rec).nodep, (2 * 3.141592653589793))
if (*rec).nodep < 0 && int64(opsmode) == int64('a') {
(*rec).nodep = (*rec).nodep + 2*3.141592653589793
}
xls = (*rec).mp + (*rec).argpp + cosip*(*rec).nodep
dls = pl + pgh - pinc*(*rec).nodep*sinip
xls = xls + dls
xls = math.Mod(xls, (2 * 3.141592653589793))
xnoh = (*rec).nodep
(*rec).nodep = math.Atan2(alfdp, betdp)
if (*rec).nodep < 0 && int64(opsmode) == int64('a') {
(*rec).nodep = (*rec).nodep + 2*3.141592653589793
}
if math.Abs(xnoh-(*rec).nodep) > 3.141592653589793 {
if (*rec).nodep < xnoh {
(*rec).nodep = (*rec).nodep + 2*3.141592653589793
} else {
(*rec).nodep = (*rec).nodep - 2*3.141592653589793
}
}
(*rec).mp = (*rec).mp + pl
(*rec).argpp = xls - (*rec).mp - cosip*(*rec).nodep
}
}
}
// dscom - transpiled function from /home/somebody/aholinch/sgp4/src/c/all.c:543
/*-----------------------------------------------------------------------------
*
* procedure dscom
*
* this procedure provides deep space common items used by both the secular
* and periodics subroutines. input is provided as shown. this routine
* used to be called dpper, but the functions inside weren't well organized.
*
* author : david vallado 719-573-2600 28 jun 2005
*
* inputs :
* epoch -
* ep - eccentricity
* argpp - argument of perigee
* tc -
* inclp - inclination
* nodep - right ascension of ascending node
* np - mean motion
*
* outputs :
* sinim , cosim , sinomm , cosomm , snodm , cnodm
* day -
* e3 -
* ee2 -
* em - eccentricity
* emsq - eccentricity squared
* gam -
* peo -
* pgho -
* pho -
* pinco -
* plo -
* rtemsq -
* se2, se3 -
* sgh2, sgh3, sgh4 -
* sh2, sh3, si2, si3, sl2, sl3, sl4 -
* s1, s2, s3, s4, s5, s6, s7 -
* ss1, ss2, ss3, ss4, ss5, ss6, ss7, sz1, sz2, sz3 -
* sz11, sz12, sz13, sz21, sz22, sz23, sz31, sz32, sz33 -
* xgh2, xgh3, xgh4, xh2, xh3, xi2, xi3, xl2, xl3, xl4 -
* nm - mean motion
* z1, z2, z3, z11, z12, z13, z21, z22, z23, z31, z32, z33 -
* zmol -
* zmos -
*
* locals :
* a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -
* betasq -
* cc -
* ctem, stem -
* x1, x2, x3, x4, x5, x6, x7, x8 -
* xnodce -
* xnoi -
* zcosg , zsing , zcosgl , zsingl , zcosh , zsinh , zcoshl , zsinhl ,
* zcosi , zsini , zcosil , zsinil ,
* zx -
* zy -
*
* coupling :
* none.
*
* references :
* hoots, roehrich, norad spacetrack report #3 1980
* hoots, norad spacetrack report #6 1986
* hoots, schumacher and glover 2004
* vallado, crawford, hujsak, kelso 2006
----------------------------------------------------------------------------*/ //
/* -------------------------- constants ------------------------- */ //
/* --------------------- local variables ------------------------ */ //
/* ----------------- initialize lunar solar terms --------------- */ //
/* ------------------------- do solar terms --------------------- */ //
/* ----------------------- do lunar terms ------------------- */ //
/* ------------------------ do solar terms ---------------------- */ //
/* ------------------------ do lunar terms ---------------------- */ //
// dscom
//
func dscom(epoch float64, ep float64, argpp float64, tc float64, inclp float64, nodep float64, np float64, rec *elsetRec) {
var zes float64 = 0.01675
var zel float64 = 0.0549
var c1ss float64 = 2.9864797e-06
var c1l float64 = 4.7968065e-07
var zsinis float64 = 0.39785416
var zcosis float64 = 0.91744867
var zcosgs float64 = 0.1945905
var zsings float64 = -0.98088458
var lsflg int64
var a1 float64
var a2 float64
var a3 float64
var a4 float64
var a5 float64
var a6 float64
var a7 float64
var a8 float64
var a9 float64
var a10 float64
var betasq float64
var cc float64
var ctem float64
var stem float64
var x1 float64
var x2 float64
var x3 float64
var x4 float64
var x5 float64
var x6 float64
var x7 float64
var x8 float64
var xnodce float64
var xnoi float64
var zcosg float64
var zcosgl float64
var zcosh float64
var zcoshl float64
var zcosi float64
var zcosil float64
var zsing float64
var zsingl float64
var zsinh float64
var zsinhl float64
var zsini float64
var zsinil float64
var zx float64
var zy float64
(*rec).nm = np
(*rec).em = ep
(*rec).snodm = math.Sin(nodep)
(*rec).cnodm = math.Cos(nodep)
(*rec).sinomm = math.Sin(argpp)
(*rec).cosomm = math.Cos(argpp)
(*rec).sinim = math.Sin(inclp)
(*rec).cosim = math.Cos(inclp)
(*rec).emsq = (*rec).em * (*rec).em
betasq = 1 - (*rec).emsq
(*rec).rtemsq = math.Sqrt(betasq)
(*rec).peo = 0
(*rec).pinco = 0
(*rec).plo = 0
(*rec).pgho = 0
(*rec).pho = 0
(*rec).day = epoch + 18261.5 + tc/1440
xnodce = math.Mod(4.523602-0.00092422029*(*rec).day, (2 * 3.141592653589793))
stem = math.Sin(xnodce)
ctem = math.Cos(xnodce)
zcosil = 0.91375164 - 0.03568096*ctem