/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sofars-0.6.1/src/ts/tcbtdb.rs
Line | Count | Source |
1 | | use crate::consts::{DAYSEC, DJM0, DJM77, ELB, TDB0, TTMTAI}; |
2 | | |
3 | | /// Time scale transformation: Barycentric Coordinate Time, TCB, to |
4 | | /// Barycentric Dynamical Time, TDB. |
5 | | /// |
6 | | /// This function is part of the International Astronomical Union's |
7 | | /// SOFA (Standards of Fundamental Astronomy) software collection. |
8 | | /// |
9 | | /// Status: canonical. |
10 | | /// |
11 | | /// Given: |
12 | | /// tcb1,tcb2 double TCB as a 2-part Julian Date |
13 | | /// |
14 | | /// Returned: |
15 | | /// tdb1,tdb2 double TDB as a 2-part Julian Date |
16 | | /// |
17 | | /// Returned (function value): |
18 | | /// int status: 0 = OK |
19 | | /// |
20 | 0 | pub fn tcbtdb(tcb1: f64, tcb2: f64) -> Result<(f64, f64), i32> { |
21 | | /* 1977 Jan 1 00:00:32.184 TT, as two-part JD */ |
22 | | const T77TD: f64 = DJM0 + DJM77; |
23 | 0 | let t77tf: f64 = TTMTAI / DAYSEC; |
24 | | |
25 | | /* TDB (days) at TAI 1977 Jan 1.0 */ |
26 | 0 | let tdb0_val: f64 = TDB0 / DAYSEC; |
27 | | |
28 | | let d; |
29 | | let (tdb1, tdb2); |
30 | | |
31 | | /* Result, safeguarding precision. */ |
32 | 0 | if tcb1.abs() > tcb2.abs() { |
33 | 0 | d = tcb1 - T77TD; |
34 | 0 | tdb1 = tcb1; |
35 | 0 | tdb2 = tcb2 + tdb0_val - (d + (tcb2 - t77tf)) * ELB; |
36 | 0 | } else { |
37 | 0 | d = tcb2 - T77TD; |
38 | 0 | tdb1 = tcb1 + tdb0_val - (d + (tcb1 - t77tf)) * ELB; |
39 | 0 | tdb2 = tcb2; |
40 | 0 | } |
41 | | |
42 | 0 | Ok((tdb1, tdb2)) |
43 | 0 | } |