/
p.jl
2669 lines (1957 loc) · 79.6 KB
/
p.jl
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
"""
pmpx(rc, dc, pr, pd, px, rv, pmt, vob)
Proper motion and parallax.
### Given ###
- `rc`, `dc`: ICRS RA,Dec at catalog epoch (radians)
- `pr`: RA proper motion (radians/year; Note 1)
- `pd`: Dec proper motion (radians/year)
- `px`: Parallax (arcsec)
- `rv`: Radial velocity (km/s, +ve if receding)
- `pmt`: Proper motion time interval (SSB, Julian years)
- `vob`: SSB to observer vector (au)
### Returned ###
- `pco`: Coordinate direction (BCRS unit vector)
### Notes ###
1. The proper motion in RA is dRA/dt rather than cos(Dec)*dRA/dt.
2. The proper motion time interval is for when the starlight
reaches the solar system barycenter.
3. To avoid the need for iteration, the Roemer effect (i.e. the
small annual modulation of the proper motion coming from the
changing light time) is applied approximately, using the
direction of the star at the catalog epoch.
### References ###
- 1984 Astronomical Almanac, pp B39-B41.
- Urban, S. & Seidelmann, P. K. (eds), Explanatory Supplement to
the Astronomical Almanac, 3rd ed., University Science Books
(2013), Section 7.2.
### Called ###
- [`pdp`](@ref): scalar product of two p-vectors
- [`pn`](@ref): decompose p-vector into modulus and direction
"""
function pmpx(rc, dc, pr, pd, px, rv, pmt, vob)
@checkdims 3 vob
pco = zeros(Cdouble, 3)
ccall((:eraPmpx, liberfa), Cvoid,
(Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}),
rc, dc, pr, pd, px, rv, pmt, vob, pco)
return pco
end
"""
p06e(date1, date2)
Precession angles, IAU 2006, equinox based.
### Given ###
- `date1`, `date2`: TT as a 2-part Julian Date (Note 1)
### Returned (see Note 2) ###
- `eps0`: epsilon_0
- `psia`: psi_A
- `oma`: omega_A
- `bpa`: P_A
- `bqa`: Q_A
- `pia`: pi_A
- `bpia`: Pi_A
- `epsa`: obliquity epsilon_A
- `chia`: chi_A
- `za`: z_A
- `zetaa`: zeta_A
- `thetaa`: theta_A
- `pa`: p_A
- `gam`: F-W angle gamma_J2000
- `phi`: F-W angle phi_J2000
- `psi`: F-W angle psi_J2000
### Notes ###
1. The TT date date1+date2 is a Julian Date, apportioned in any
convenient way between the two arguments. For example,
JD(TT)=2450123.7 could be expressed in any of these ways,
among others:
| `date1` | `date2` | Method |
|:----------|:------------|:------------|
| 2450123.7 | 0.0 | JD |
| 2451545.0 | -1421.3 | J2000 |
| 2400000.5 | 50123.2 | MJD |
| 2450123.5 | 0.2 | date & time |
The JD method is the most natural and convenient to use in
cases where the loss of several decimal digits of resolution
is acceptable. The J2000 method is best matched to the way
the argument is handled internally and will deliver the
optimum resolution. The MJD method and the date & time methods
are both good compromises between resolution and convenience.
2. This function returns the set of equinox based angles for the
Capitaine et al. "P03" precession theory, adopted by the IAU in 2006.
The angles are set out in Table 1 of Hilton et al. (2006):
| Angle | Name | Description |
|:---------|:--------------|:-----------------------------------------------|
| eps0 | epsilon_0 | obliquity at J2000.0 |
| psia | psi_A | luni-solar precession |
| oma | omega_A | inclination of equator wrt J2000.0 ecliptic |
| bpa | P_A | ecliptic pole x, J2000.0 ecliptic triad |
| bqa | Q_A | ecliptic pole -y, J2000.0 ecliptic triad |
| pia | pi_A | angle between moving and J2000.0 ecliptics |
| bpia | Pi_A | longitude of ascending node of the ecliptic |
| epsa | epsilon_A | obliquity of the ecliptic |
| chia | chi_A | planetary precession |
| za | z_A | equatorial precession: -3rd 323 Euler angle |
| zetaa | zeta_A | equatorial precession: -1st 323 Euler angle |
| thetaa | theta_A | equatorial precession: 2nd 323 Euler angle |
| pa | p_A | general precession |
| gam | gamma_J2000 | J2000.0 RA difference of ecliptic poles |
| phi | phi_J2000 | J2000.0 codeclination of ecliptic pole |
| psi | psi_J2000 | longitude difference of equator poles, J2000.0 |
The returned values are all radians.
3. Hilton et al. (2006) Table 1 also contains angles that depend on
models distinct from the P03 precession theory itself, namely the
IAU 2000A frame bias and nutation. The quoted polynomials are
used in other ERFA functions:
- [`xy06`](@ref) contains the polynomial parts of the X and Y series.
- [`s06`](@ref) contains the polynomial part of the s+XY/2 series.
- [`pfw06`](@ref) implements the series for the Fukushima-Williams
angles that are with respect to the GCRS pole (i.e. the variants
that include frame bias).
4. The IAU resolution stipulated that the choice of parameterization
was left to the user, and so an IAU compliant precession
implementation can be constructed using various combinations of
the angles returned by the present function.
5. The parameterization used by ERFA is the version of the Fukushima-
Williams angles that refers directly to the GCRS pole. These
angles may be calculated by calling the function [`pfw06`](@ref). ERFA
also supports the direct computation of the CIP GCRS X,Y by
series, available by calling [`xy06`](@ref).
6. The agreement between the different parameterizations is at the
1 microarcsecond level in the present era.
7. When constructing a precession formulation that refers to the GCRS
pole rather than the dynamical pole, it may (depending on the
choice of angles) be necessary to introduce the frame bias
explicitly.
8. It is permissible to re-use the same variable in the returned
arguments. The quantities are stored in the stated order.
### Reference ###
- Hilton, J. et al., 2006, Celest.Mech.Dyn.Astron. 94, 351
### Called ###
- [`obl06`](@ref): mean obliquity, IAU 2006
"""
function p06e(date1, date2)
eps0 = Ref{Cdouble}()
psia = Ref{Cdouble}()
oma = Ref{Cdouble}()
bpa = Ref{Cdouble}()
bqa = Ref{Cdouble}()
pia = Ref{Cdouble}()
bpia = Ref{Cdouble}()
epsa = Ref{Cdouble}()
chia = Ref{Cdouble}()
za = Ref{Cdouble}()
zetaa = Ref{Cdouble}()
thetaa = Ref{Cdouble}()
pa = Ref{Cdouble}()
gam = Ref{Cdouble}()
phi = Ref{Cdouble}()
psi = Ref{Cdouble}()
ccall((:eraP06e, liberfa), Cvoid,
(Cdouble, Cdouble, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble},
Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}),
date1, date2, eps0, psia, oma, bpa, bqa, pia, bpia, epsa, chia, za, zetaa, thetaa, pa, gam, phi, psi)
return eps0[], psia[], oma[], bpa[], bqa[], pia[], bpia[], epsa[], chia[], za[], zetaa[], thetaa[], pa[], gam[], phi[], psi[]
end
"""
p2s(p)
P-vector to spherical polar coordinates.
### Given ###
- `p`: P-vector
### Returned ###
- `theta`: Longitude angle (radians)
- `phi`: Latitude angle (radians)
- `r`: Radial distance
### Notes ###
1. If P is null, zero theta, phi and r are returned.
2. At either pole, zero theta is returned.
### Called ###
- [`c2s`](@ref): p-vector to spherical
- [`pm`](@ref): modulus of p-vector
"""
function p2s(p)
@checkdims 3 p
theta = Ref{Cdouble}()
phi = Ref{Cdouble}()
r = Ref{Cdouble}()
ccall((:eraP2s, liberfa), Cvoid,
(Ptr{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}),
p, theta, phi, r)
return theta[], phi[], r[]
end
"""
p2pv(p)
!!! warning "Deprecated"
Use `[p, zeros(3)]` instead.
Extend a p-vector to a pv-vector by appending a zero velocity.
### Given ###
- `p`: P-vector
### Returned ###
- `pv`: Pv-vector
### Called ###
- [`erfa_cp`](@ref): copy p-vector
- [`zp`](@ref): zero p-vector
"""
p2pv
function _p2pv(p)
@checkdims 3 p
pv = zeros(Cdouble, 3, 2)
ccall((:eraP2pv, liberfa), Cvoid,
(Ptr{Cdouble}, Ptr{Cdouble}),
p, pv)
return cmatrix_to_array(pv)
end
@deprecate p2pv(p) [p, zeros(3)]
"""
pb06(date1, date2)
This function forms three Euler angles which implement general
precession from epoch J2000.0, using the IAU 2006 model. Frame
bias (the offset between ICRS and mean J2000.0) is included.
### Given ###
- `date1`, `date2`: TT as a 2-part Julian Date (Note 1)
### Returned ###
- `bzeta`: 1st rotation: radians cw around z
- `bz`: 3rd rotation: radians cw around z
- `btheta`: 2nd rotation: radians ccw around y
### Notes ###
1. The TT date date1+date2 is a Julian Date, apportioned in any
convenient way between the two arguments. For example,
JD(TT)=2450123.7 could be expressed in any of these ways,
among others:
| `date1` | `date2` | Method |
|:----------|:------------|:------------|
| 2450123.7 | 0.0 | JD |
| 2451545.0 | -1421.3 | J2000 |
| 2400000.5 | 50123.2 | MJD |
| 2450123.5 | 0.2 | date & time |
The JD method is the most natural and convenient to use in
cases where the loss of several decimal digits of resolution
is acceptable. The J2000 method is best matched to the way
the argument is handled internally and will deliver the
optimum resolution. The MJD method and the date & time methods
are both good compromises between resolution and convenience.
2. The traditional accumulated precession angles zeta_A, z_A,
theta_A cannot be obtained in the usual way, namely through
polynomial expressions, because of the frame bias. The latter
means that two of the angles undergo rapid changes near this
date. They are instead the results of decomposing the
precession-bias matrix obtained by using the Fukushima-Williams
method, which does not suffer from the problem. The
decomposition returns values which can be used in the
conventional formulation and which include frame bias.
3. The three angles are returned in the conventional order, which
is not the same as the order of the corresponding Euler
rotations. The precession-bias matrix is
`R_3(-z) x R_2(+theta) x R_3(-zeta)`.
4. Should `zeta_A`, `z_A`, `theta_A` angles be required that do not
contain frame bias, they are available by calling the ERFA
function [`p06e`](@ref).
### Called ###
- [`pmat06`](@ref): PB matrix, IAU 2006
- [`rz`](@ref): rotate around Z-axis
"""
function pb06(date1, date2)
bzeta = Ref{Cdouble}()
bz = Ref{Cdouble}()
btheta = Ref{Cdouble}()
ccall((:eraPb06, liberfa), Cvoid,
(Cdouble, Cdouble, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}),
date1, date2, bzeta, bz, btheta)
return bzeta[], bz[], btheta[]
end
"""
pfw06(date1, date2)
Precession angles, IAU 2006 (Fukushima-Williams 4-angle formulation).
### Given ###
- `date1`, `date2`: TT as a 2-part Julian Date (Note 1)
### Returned ###
- `gamb`: F-W angle gamma_bar (radians)
- `phib`: F-W angle phi_bar (radians)
- `psib`: F-W angle psi_bar (radians)
- `epsa`: F-W angle epsilon_A (radians)
### Notes ###
1. The TT date date1+date2 is a Julian Date, apportioned in any
convenient way between the two arguments. For example,
JD(TT)=2450123.7 could be expressed in any of these ways,
among others:
| `date1` | `date2` | Method |
|:----------|:------------|:------------|
| 2450123.7 | 0.0 | JD |
| 2451545.0 | -1421.3 | J2000 |
| 2400000.5 | 50123.2 | MJD |
| 2450123.5 | 0.2 | date & time |
The JD method is the most natural and convenient to use in
cases where the loss of several decimal digits of resolution
is acceptable. The J2000 method is best matched to the way
the argument is handled internally and will deliver the
optimum resolution. The MJD method and the date & time methods
are both good compromises between resolution and convenience.
2. Naming the following points:
- e = J2000.0 ecliptic pole,
- p = GCRS pole,
- E = mean ecliptic pole of date,
- and P = mean pole of date,
the four Fukushima-Williams angles are as follows:
- gamb = gamma_bar = epE
- phib = phi_bar = pE
- psib = psi_bar = pEP
- epsa = epsilon_A = EP
3. The matrix representing the combined effects of frame bias and
precession is:
```
PxB = R_1(-epsa).R_3(-psib).R_1(phib).R_3(gamb)
```
4. The matrix representing the combined effects of frame bias,
precession and nutation is simply:
```
NxPxB = R_1(-epsa-dE).R_3(-psib-dP).R_1(phib).R_3(gamb)
```
where dP and dE are the nutation components with respect to the
ecliptic of date.
### Reference ###
- Hilton, J. et al., 2006, Celest.Mech.Dyn.Astron. 94, 351
### Called ###
- [`obl06`](@ref): mean obliquity, IAU 2006
"""
function pfw06(date1, date2)
gamb = Ref{Cdouble}()
phib = Ref{Cdouble}()
psib = Ref{Cdouble}()
epsa = Ref{Cdouble}()
ccall((:eraPfw06, liberfa), Cvoid,
(Cdouble, Cdouble, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}),
date1, date2, gamb, phib, psib, epsa)
return gamb[], phib[], psib[], epsa[]
end
"""
plan94(date1, date2, np)
Approximate heliocentric position and velocity of a nominated major
planet: Mercury, Venus, EMB, Mars, Jupiter, Saturn, Uranus or
Neptune (but not the Earth itself).
### Given ###
- `date1`: TDB date part A (Note 1)
- `date2`: TDB date part B (Note 1)
- `np`: Planet (1=Mercury, 2=Venus, 3=EMB, 4=Mars,
5=Jupiter, 6=Saturn, 7=Uranus, 8=Neptune)
### Returned (argument) ###
- Planet `p,v` (heliocentric, J2000.0, au,au/d)
### Notes ###
1. The date date1+date2 is in the TDB time scale (in practice TT can
be used) and is a Julian Date, apportioned in any convenient way
between the two arguments. For example, JD(TDB)=2450123.7 could
be expressed in any of these ways, among others:
| `date1` | `date2` | Method |
|:----------|:------------|:------------|
| 2450123.7 | 0.0 | JD |
| 2451545.0 | -1421.3 | J2000 |
| 2400000.5 | 50123.2 | MJD |
| 2450123.5 | 0.2 | date & time |
The JD method is the most natural and convenient to use in cases
where the loss of several decimal digits of resolution is
acceptable. The J2000 method is best matched to the way the
argument is handled internally and will deliver the optimum
resolution. The MJD method and the date & time methods are both
good compromises between resolution and convenience. The limited
accuracy of the present algorithm is such that any of the methods
is satisfactory.
2. If an np value outside the range 1-8 is supplied, an error status
(function value -1) is returned and the pv vector set to zeroes.
3. For np=3 the result is for the Earth-Moon Barycenter. To obtain
the heliocentric position and velocity of the Earth, use instead
the ERFA function [`epv00`](@ref).
4. On successful return, the arrays `p` and `v` contain the following:
- `p`: heliocentric position, au
- `v`: heliocentric velocity, au/d
The reference frame is equatorial and is with respect to the
mean equator and equinox of epoch J2000.0.
5. The algorithm is due to J.L. Simon, P. Bretagnon, J. Chapront,
M. Chapront-Touze, G. Francou and J. Laskar (Bureau des
Longitudes, Paris, France). From comparisons with JPL
ephemeris DE102, they quote the following maximum errors
over the interval 1800-2050:
| Body | L (arcsec) | B (arcsec) | R (km) |
|:--------------|:------------|:-----------|:-------|
| Mercury | 4 | 1 | 300 |
| Venus | 5 | 1 | 800 |
| EMB | 6 | 1 | 1000 |
| Mars | 17 | 1 | 7700 |
| Jupiter | 71 | 5 | 76000 |
| Saturn | 81 | 13 | 267000 |
| Uranus | 86 | 7 | 712000 |
| Neptune | 11 | 1 | 253000 |
Over the interval 1000-3000, they report that the accuracy is no
worse than 1.5 times that over 1800-2050. Outside 1000-3000 the
accuracy declines.
Comparisons of the present function with the JPL DE200 ephemeris
give the following RMS errors over the interval 1960-2025:
| Body | position (km) | velocity (m/s) |
|:-------------|:----------------|:---------------|
| Mercury | 334 | 0.437 |
| Venus | 1060 | 0.855 |
| EMB | 2010 | 0.815 |
| Mars | 7690 | 1.98 |
| Jupiter | 71700 | 7.70 |
| Saturn | 199000 | 19.4 |
| Uranus | 564000 | 16.4 |
| Neptune | 158000 | 14.4 |
Comparisons against DE200 over the interval 1800-2100 gave the
following maximum absolute differences. (The results using
DE406 were essentially the same.)
| Body | L (arcsec) | B (arcsec) | R (km) | Rdot (m/s) |
|:----------|:-----------|:------------|:--------|:-----------|
| Mercury | 7 | 1 | 500 | 0.7 |
| Venus | 7 | 1 | 1100 | 0.9 |
| EMB | 9 | 1 | 1300 | 1.0 |
| Mars | 26 | 1 | 9000 | 2.5 |
| Jupiter | 78 | 6 | 82000 | 8.2 |
| Saturn | 87 | 14 | 263000 | 24.6 |
| Uranus | 86 | 7 | 661000 | 27.4 |
| Neptune | 11 | 2 | 248000 | 21.4 |
6. The present ERFA re-implementation of the original Simon et al.
Fortran code differs from the original in the following respects:
- C instead of Fortran.
- The date is supplied in two parts.
- The result is returned only in equatorial Cartesian form;
the ecliptic longitude, latitude and radius vector are not
returned.
- The result is in the J2000.0 equatorial frame, not ecliptic.
- More is done in-line: there are fewer calls to subroutines.
- Different error/warning status values are used.
- A different Kepler's-equation-solver is used (avoiding
use of double precision complex).
- Polynomials in t are nested to minimize rounding errors.
- Explicit double constants are used to avoid mixed-mode
expressions.
None of the above changes affects the result significantly.
7. The returned status indicates the most serious condition
encountered during execution of the function. Illegal np is
considered the most serious, overriding failure to converge,
which in turn takes precedence over the remote date warning.
### Called ###
- [`anp`](@ref): normalize angle into range 0 to 2pi
### Reference ###
- Simon, J.L, Bretagnon, P., Chapront, J., Chapront-Touze, M.,
Francou, G., and Laskar, J., Astron. Astrophys. 282, 663 (1994).
"""
function plan94(date1, date2, np)
pv = zeros(Cdouble, 3, 2)
i = ccall((:eraPlan94, liberfa), Cint,
(Cdouble, Cdouble, Cint, Ptr{Cdouble}),
date1, date2, np, pv)
if i == -1
throw(ERFAException("illegal np, not in range(1,8) for planet"))
elseif i == 1
@warn "year outside range(1000:3000)"
elseif i == 2
throw(ERFAException("computation failed to converge"))
elseif i == 0
# pass
end
return cmatrix_to_array(pv)
end
"""
pm(p)
Modulus of p-vector.
!!! warning "Deprecated"
Use `LinearAlgebra.norm` instead.
### Given ###
- `p`: P-vector
### Returned ###
- Modulus
"""
pm
function _pm(p)
@checkdims 3 p
return ccall((:eraPm, liberfa), Cdouble, (Ptr{Cdouble},), p)
end
@deprecate pm norm
"""
pmsafe(ra1, dec1, pmr1, pmd1, px1, rv1, ep1a, ep1b, ep2a, ep2b)
Star proper motion: update star catalog data for space motion, with
special handling to handle the zero parallax case.
### Given ###
- `ra1`: Right ascension (radians), before
- `dec1`: Declination (radians), before
- `pmr1`: RA proper motion (radians/year), before
- `pmd1`: Dec proper motion (radians/year), before
- `px1`: Parallax (arcseconds), before
- `rv1`: Radial velocity (km/s, +ve = receding), before
- `ep1a`: "before" epoch, part A (Note 1)
- `ep1b`: "before" epoch, part B (Note 1)
- `ep2a`: "after" epoch, part A (Note 1)
- `ep2b`: "after" epoch, part B (Note 1)
### Returned ###
- `ra2`: Right ascension (radians), after
- `dec2`: Declination (radians), after
- `pmr2`: RA proper motion (radians/year), after
- `pmd2`: Dec proper motion (radians/year), after
- `px2`: Parallax (arcseconds), after
- `rv2`: Radial velocity (km/s, +ve = receding), after
### Notes ###
1. The starting and ending TDB epochs ep1a+ep1b and ep2a+ep2b are
Julian Dates, apportioned in any convenient way between the two
parts (A and B). For example, JD(TDB)=2450123.7 could be
expressed in any of these ways, among others:
| `epNa` | `epNb` | Method |
|:----------|:------------|:------------|
| 2450123.7 | 0.0 | JD |
| 2451545.0 | -1421.3 | J2000 |
| 2400000.5 | 50123.2 | MJD |
| 2450123.5 | 0.2 | date & time |
The JD method is the most natural and convenient to use in cases
where the loss of several decimal digits of resolution is
acceptable. The J2000 method is best matched to the way the
argument is handled internally and will deliver the optimum
resolution. The MJD method and the date & time methods are both
good compromises between resolution and convenience.
2. In accordance with normal star-catalog conventions, the object's
right ascension and declination are freed from the effects of
secular aberration. The frame, which is aligned to the catalog
equator and equinox, is Lorentzian and centered on the SSB.
The proper motions are the rate of change of the right ascension
and declination at the catalog epoch and are in radians per TDB
Julian year.
The parallax and radial velocity are in the same frame.
3. Care is needed with units. The star coordinates are in radians
and the proper motions in radians per Julian year, but the
parallax is in arcseconds.
4. The RA proper motion is in terms of coordinate angle, not true
angle. If the catalog uses arcseconds for both RA and Dec proper
motions, the RA proper motion will need to be divided by cos(Dec)
before use.
5. Straight-line motion at constant speed, in the inertial frame, is
assumed.
6. An extremely small (or zero or negative) parallax is overridden
to ensure that the object is at a finite but very large distance,
but not so large that the proper motion is equivalent to a large
but safe speed (about 0.1c using the chosen constant). A warning
status of 1 is added to the status if this action has been taken.
7. If the space velocity is a significant fraction of c (see the
constant VMAX in the function [`starpv`](@ref)), it is arbitrarily set
to zero. When this action occurs, 2 is added to the status.
8. The relativistic adjustment carried out in the [`starpv`](@ref) function
involves an iterative calculation. If the process fails to
converge within a set number of iterations, 4 is added to the
status.
### Called ###
- [`seps`](@ref): angle between two points
- [`starpm`](@ref): update star catalog data for space motion
"""
function pmsafe(ra1, dec1, pmr1, pmd1, px1, rv1, ep1a, ep1b, ep2a, ep2b)
ra2 = Ref{Cdouble}()
dec2 = Ref{Cdouble}()
pmr2 = Ref{Cdouble}()
pmd2 = Ref{Cdouble}()
px2 = Ref{Cdouble}()
rv2 = Ref{Cdouble}()
i = ccall((:eraPmsafe, liberfa), Cint,
(Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble,
Cdouble, Cdouble, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble},
Ref{Cdouble}, Ref{Cdouble}),
ra1, dec1, pmr1, pmd1, px1, rv1, ep1a, ep1b, ep2a, ep2b, ra2, dec2, pmr2,
pmd2, px2, rv2)
if i == -1
throw(ERFAException("system error"))
elseif i == 1
@warn "distance overridden"
elseif i == 2
@warn "excessive velocity"
elseif i == 4
throw(ERFAException("solution didn't converge"))
end
return ra2[], dec2[], pmr2[], pmd2[], px2[], rv2[]
end
"""
pn(p)
Convert a p-vector into modulus and unit vector.
!!! warning "Deprecated"
Use `(LinearAlgebra.norm(p), LinearAlgebra.normalize(p))` instead.
### Given ###
- `p`: P-vector
### Returned ###
- `r`: Modulus
- `u`: Unit vector
### Notes ###
1. If p is null, the result is null. Otherwise the result is a unit
vector.
2. It is permissible to re-use the same array for any of the
arguments.
### Called ###
- [`pm`](@ref): modulus of p-vector
- [`zp`](@ref): zero p-vector
- [`sxp`](@ref): multiply p-vector by scalar
"""
pn
function _pn(p)
@checkdims 3 p
r = Ref{Cdouble}()
u = zeros(Cdouble, 3)
ccall((:eraPn, liberfa), Cvoid,
(Ptr{Cdouble}, Ref{Cdouble}, Ptr{Cdouble}),
p, r, u)
return r[], u
end
@deprecate pn(p) (norm(p), normalize(p))
"""
ppsp(a, s, b)
P-vector plus scaled p-vector.
!!! warning "Deprecated"
Use `a .+ s .* b` instead.
### Given ###
- `a`: First p-vector
- `s`: Scalar (multiplier for b)
- `b`: Second p-vector
### Returned ###
- `apsb`: a + s*b
### Note ###
It is permissible for any of a, b and apsb to be the same array.
### Called ###
- [`sxp`](@ref): multiply p-vector by scalar
- [`ppp`](@ref): p-vector plus p-vector
"""
ppsp
function _ppsp(a, s, b)
@checkdims 3 a b
apsb = zeros(Cdouble, 3)
ccall((:eraPpsp, liberfa), Cvoid,
(Ptr{Cdouble}, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}),
a, s, b, apsb)
return apsb
end
@deprecate ppsp(a, s, b) a .+ s .* b
"""
prec76(date01, date02, date11, date12)
IAU 1976 precession model.
This function forms the three Euler angles which implement general
precession between two dates, using the IAU 1976 model (as for the
FK5 catalog).
### Given ###
- `date01`, `date02`: TDB starting date (Note 1)
- `date11`, `date12`: TDB ending date (Note 1)
### Returned ###
- `zeta`: 1st rotation: radians cw around z
- `z`: 3rd rotation: radians cw around z
- `theta`: 2nd rotation: radians ccw around y
### Notes ###
1. The dates date01+date02 and date11+date12 are Julian Dates,
apportioned in any convenient way between the arguments daten1
and daten2. For example, JD(TDB)=2450123.7 could be expressed in
any of these ways, among others:
| `daten1` | `daten2` | Method |
|:----------|:------------|:------------|
| 2450123.7 | 0.0 | JD |
| 2451545.0 | -1421.3 | J2000 |
| 2400000.5 | 50123.2 | MJD |
| 2450123.5 | 0.2 | date & time |
The JD method is the most natural and convenient to use in cases
where the loss of several decimal digits of resolution is
acceptable. The J2000 method is best matched to the way the
argument is handled internally and will deliver the optimum
optimum resolution. The MJD method and the date & time methods
are both good compromises between resolution and convenience.
The two dates may be expressed using different methods, but at
the risk of losing some resolution.
2. The accumulated precession angles zeta, z, theta are expressed
through canonical polynomials which are valid only for a limited
time span. In addition, the IAU 1976 precession rate is known to
be imperfect. The absolute accuracy of the present formulation
is better than 0.1 arcsec from 1960AD to 2040AD, better than
1 arcsec from 1640AD to 2360AD, and remains below 3 arcsec for
the whole of the period 500BC to 3000AD. The errors exceed
10 arcsec outside the range 1200BC to 3900AD, exceed 100 arcsec
outside 4200BC to 5600AD and exceed 1000 arcsec outside 6800BC to
8200AD.
3. The three angles are returned in the conventional order, which
is not the same as the order of the corresponding Euler
rotations. The precession matrix is
`R_3(-z) x R_2(+theta) x R_3(-zeta)`.
### Reference ###
- Lieske, J.H., 1979, Astron.Astrophys. 73, 282, equations
(6) & (7), p283.
"""
function prec76(ep01, ep02, ep11, ep12)
zeta = Ref{Cdouble}()
z = Ref{Cdouble}()
theta = Ref{Cdouble}()
ccall((:eraPrec76, liberfa), Cvoid,
(Cdouble, Cdouble, Cdouble, Cdouble, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}),
ep01, ep02, ep11, ep12, zeta, z, theta)
return zeta[], z[], theta[]
end
"""
pv2s(pv)
Convert position/velocity from Cartesian to spherical coordinates.
### Given ###
- `pv`: Pv-vector
### Returned ###
- `theta`: Longitude angle (radians)
- `phi`: Latitude angle (radians)
- `r`: Radial distance
- `td`: Rate of change of theta
- `pd`: Rate of change of phi
- `rd`: Rate of change of r
### Notes ###
1. If the position part of pv is null, theta, phi, td and pd
are indeterminate. This is handled by extrapolating the
position through unit time by using the velocity part of
pv. This moves the origin without changing the direction
of the velocity component. If the position and velocity
components of pv are both null, zeroes are returned for all
six results.
2. If the position is a pole, theta, td and pd are indeterminate.
In such cases zeroes are returned for all three.
"""
function pv2s(pv)
_pv = array_to_cmatrix(pv; n=3)
theta = Ref{Cdouble}()
phi = Ref{Cdouble}()
r = Ref{Cdouble}()
td = Ref{Cdouble}()
pd = Ref{Cdouble}()
rd = Ref{Cdouble}()
ccall((:eraPv2s, liberfa), Cvoid,
(Ptr{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}),
_pv, theta, phi, r, td, pd, rd)
return theta[], phi[], r[], td[], pd[], rd[]
end
"""
pv2p(pv)
Discard velocity component of a pv-vector.
!!! warning "Deprecated"
Use `first(pv)` instead.
### Given ###
- `pv`: Pv-vector
### Returned ###
- `p`: P-vector
### Called ###
- [`erfa_cp`](@ref): copy p-vector
"""
pv2p
function _pv2p(pv)
_pv = array_to_cmatrix(pv; n=3)
p = zeros(Cdouble, 3)
ccall((:eraPv2p, liberfa), Cvoid,
(Ptr{Cdouble}, Ptr{Cdouble}),
_pv, p)
return p
end
@deprecate pv2p first
"""
pvdpv(a, b)
Inner (=scalar=dot) product of two pv-vectors.
### Given ###
- `a`: First pv-vector
- `b`: Second pv-vector
### Returned ###
- `adb`: ``a \\cdot b`` (see note)
### Note ###
If the position and velocity components of the two pv-vectors are
( ap, av ) and ( bp, bv ), the result, a . b, is the pair of