rfa 0.5.9

A port ERFA to Rust.
Documentation
use crate::{rfam::*, utils::*};
use crate::prec_nut::{bi00::bi00, pr00::pr00};
use crate::vector_matrix::init::ir::ir;
use crate::vector_matrix::build_rotations::{rx::rx, ry::ry, rz::rz};
use crate::vector_matrix::copy_ext::*;
use crate::vector_matrix::matrix_ops::rxr::rxr;

///  Frame bias and precession, IAU 2000.
///
///  Given:
///   * date1,date2  double         TT as a 2-part Julian Date (Note 1)
///
///  Returned:
///   * rb  frame bias matrix (Note 2)
///   * rp  precession matrix (Note 3)
///   * rbp bias-precession matrix (Note 4)
///
/// # 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   |                      |
///     |-------------|--------------|----------------------|
///     |2450123.7    |       0.0    |  (JD method)         |
///     |2451545.0    |   -1421.3    |  (J2000 method)      |
///     |2400000.5    |   50123.2    |  (MJD method)        |
///     |2450123.5    |       0.2    | (date & time method) |
///
///     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 matrix rb transforms vectors from GCRS to mean J2000.0 by
///     applying frame bias.
///
///  3) The matrix rp transforms vectors from J2000.0 mean equator and
///     equinox to mean equator and equinox of date by applying
///     precession.
///
///  4) The matrix rbp transforms vectors from GCRS to mean equator and
///     equinox of date by applying frame bias then precession.  It is
///     the product rp x rb.
///
///  5) It is permissible to re-use the same array in the returned
///     arguments.  The arrays are filled in the order given.
///
/// # Called:
///   * bi00      frame bias components, IAU 2000
///   * pr00      IAU 2000 precession adjustments
///   * ir        initialize r-matrix to identity
///   * rx        rotate around X-axis
///   * ry        rotate around Y-axis
///   * rz        rotate around Z-axis
///   * cr        copy r-matrix
///   * rxr       product of two r-matrices
///
/// # Reference:
///    * "Expressions for the Celestial Intermediate Pole and Celestial
///      Ephemeris Origin consistent with the IAU 2000A precession-
///      nutation model", Astron.Astrophys. 400, 1145-1154 (2003)
///      n.b. The celestial ephemeris origin (CEO) was renamed "celestial
///          intermediate origin" (CIO) by IAU 2006 Resolution 2.
///
///  This revision:  2021 May 11
pub fn bp00(date1: f64, date2: f64,
    rb: &mut[[f64; 3]; 3], rp: &mut[[f64; 3]; 3], rbp: &mut[[f64; 3]; 3])
{
/* J2000.0 obliquity (Lieske et al. 1977) */
   const EPS0: f64 = 84381.448 * URSA_DAS2R;

/* Interval between fundamental epoch J2000.0 and current date (JC). */
   let t = ((date1 - URSA_DJ00) + date2) / URSA_DJC;

/* Frame bias. */
   let mut dpsibi = 0.0; let mut depsbi = 0.0; let mut dra0 = 0.0;
   bi00(&mut dpsibi, &mut depsbi, &mut dra0);

/* Precession angles (Lieske et al. 1977) */
   let psia77 = (5038.7784 + (-1.07259 + (-0.001147) * t) * t) * t * URSA_DAS2R;
   let oma77  =       EPS0 + ((0.05127 + (-0.007726) * t) * t) * t * URSA_DAS2R;
   let chia   = (  10.5526 + (-2.38064 + (-0.001125) * t) * t) * t * URSA_DAS2R;

/* Apply IAU 2000 precession corrections. */
   let mut dpsipr = 0.0; let mut depspr = 0.0;
   pr00(date1, date2, &mut dpsipr, &mut depspr);
   let psia = psia77 + dpsipr;
   let oma  = oma77  + depspr;
   
   let mut rbw = [[0.0; 3]; 3];
/* Frame bias matrix: GCRS to J2000.0. */
   ir(&mut rbw);
   rz(dra0, &mut rbw);
   ry(dpsibi*sin(EPS0), &mut rbw);
   rx(-depsbi, &mut rbw);
   cr(&rbw, rb);

/* Precession matrix: J2000.0 to mean of date. */
   ir(rp);
   rx(EPS0, rp);
   rz(-psia, rp);
   rx(-oma, rp);
   rz(chia, rp);

/* Bias-precession matrix: GCRS to mean of date. */
   rxr(rp, &rbw, rbp);

/* Finished. */

}