
void slaAddet ( double rm, double dm, double eq, double *rc, double *dc )
/*
**  - - - - - - - - -
**   s l a A d d e t
**  - - - - - - - - -
**
**  Add the e-terms (elliptic component of annual aberration) to a
**  pre IAU 1976 mean place to conform to the old catalogue convention.
**
**  Given:
**     rm,dm     double     RA,Dec (radians) without e-terms
**     eq        double     Besselian epoch of mean equator and equinox
**
**  Returned:
**     *rc,*dc   double     RA,dec (radians) with e-terms included
**
**  Called:
**     slaEtrms, slaDcs2c, slaDcc2s, slaDranrm, slaDrange
**
**  Explanation:
**     Most star positions from pre-1984 optical catalogues (or
**     derived from astrometry using such stars) embody the
**     e-terms.  If it is necessary to convert a formal mean
**     place (for example a pulsar timing position) to one
**     consistent with such a star catalogue, then the RA,Dec
**     should be adjusted using this function.
**
**  Reference:
**     Explanatory Supplement to the Astronomical Almanac,
**     ed P.K.Seidelmann (1992), page 169.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAfin ( char *string, int *iptr, float *a, int *j )
/*
**  - - - - - - - -
**   s l a A f i n
**  - - - - - - - -
**
**  Sexagesimal character string to angle.
**
**  (single precision)
**
**  Given:
**     string  c*(*)   string containing deg, arcmin, arcsec fields
**     iptr    int     where to start decode (1st = 1)
**
**  Returned:
**     iptr    int     advanced past the decoded angle
**     a       float   angle in radians
**     j       int     status:  0 = OK
**                             +1 = default, A unchanged
**                             -1 = bad degrees      )
**                             -2 = bad arcminutes   )  (note 3)
**                             -3 = bad arcseconds   )
**
**  Example:
**
**    argument    before                           after
**
**    string      '-57 17 44.806  12 34 56.7'      unchanged
**    iptr        1                                16 (points to 12...)
**
**    a           ?                                -1.00000f
**    j           ?                                0
**
**    A further call to slaAfin, without adjustment of iptr, will
**    decode the second angle, 12deg 34min 56.7sec.
**
**  Notes:
**
**     1)  The first three "fields" in string are degrees, arcminutes,
**         arcseconds, separated by spaces or commas.  The degrees field
**         may be signed, but not the others.  The decoding is carried
**         out by the slaDfltin function and is free-format.
**
**     2)  Successive fields may be absent, defaulting to zero.  For
**         zero status, the only combinations allowed are degrees alone,
**         degrees and arcminutes, and all three fields present.  If all
**         three fields are omitted, a status of +1 is returned and a is
**         unchanged.  In all other cases a is changed.
**
**     3)  Range checking:
**           The degrees field is not range checked.  However, it is
**           expected to be integral unless the other two fields are
**           absent.  The arcminutes field is expected to be 0-59, and
**           integral if the arcseconds field is present.  If the
**           arcseconds field is absent, the arcminutes is expected to
**           be 0-59.9999...  The arcseconds field is expected to be
**           0-59.9999...
**
**     4)  Decoding continues even when a check has failed.  Under these
**         circumstances the field takes the supplied value, defaulting
**         to zero, and the result a is computed and returned.
**
**     5)  Further fields after the three expected ones are not treated
**         as an error.  The pointer iptr is left in the correct state
**         for further decoding with the present function or with
**         slaDfltin etc.  See the example, above.
**
**     6)  If string contains hours, minutes, seconds instead of degrees
**         etc, or if the required units are turns (or days) instead of
**         radians, the result a should be multiplied as follows:
**           for        to obtain    multiply
**           string     a in         a by
**           d ' "      radians      1       =  1.0f
**           d ' "      turns        1/2pi   =  0.1591549430918953358f
**           h m s      radians      15      =  15.0f
**           h m s      days         15/2pi  =  2.3873241463784300365f
**
**  Called:  slaDfltin
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaAirmas ( double zd )
/*
**  - - - - - - - - - -
**   s l a A i r m a s
**  - - - - - - - - - -
**
**  Air mass at given zenith distance.
**
**  (double precision)
**
**  Given:
**     zd     d     observed zenith distance (radians)
**
**  The result is an estimate of the air mass, in units of that
**  at the zenith.
**
**  Notes:
**
**  1)  The "observed" zenith distance referred to above means "as
**      affected by refraction".
**
**  2)  Uses Hardie's (1962) polynomial fit to Bemporad's data for
**      the relative air mass, X, in units of thickness at the zenith
**      as tabulated by Schoenberg (1929). This is adequate for all
**      normal needs as it is accurate to better than 0.1% up to X =
**      6.8 and better than 1% up to X = 10. Bemporad's tabulated
**      values are unlikely to be trustworthy to such accuracy
**      because of variations in density, pressure and other
**      conditions in the atmosphere from those assumed in his work.
**
**  3)  The sign of the ZD is ignored.
**
**  4)  At zenith distances greater than about ZD = 87 degrees the
**      air mass is held constant to avoid arithmetic overflows.
**
**  References:
**     Hardie, R.H., 1962, in "Astronomical Techniques"
**        ed. W.A. Hiltner, University of Chicago Press, p180.
**     Schoenberg, E., 1929, Hdb. d. Ap.,
**        Berlin, Julius Springer, 2, 268.
**
**  Adapted from original Fortran code by P.W.Hill, St Andrews.
**
**  Last revision:   5 October 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAltaz ( double ha, double dec, double phi,
                double *az, double *azd, double *azdd,
                double *el, double *eld, double *eldd,
                double *pa, double *pad, double *padd )
/*
**  - - - - - - - - -
**   s l a A l t a z
**  - - - - - - - - -
**
**  Positions, velocities and accelerations for an altazimuth
**  telescope mount that is tracking a star.
**
**  (double precision)
**
**  Given:
**     ha          double      hour angle
**     dec         double      declination
**     phi         double      latitude
**
**  Returned:
**     *az         double      azimuth
**     *azd        double         "    velocity
**     *azdd       double         "    acceleration
**     *el         double      elevation
**     *eld        double          "     velocity
**     *eldd       double          "     acceleration
**     *pa         double      parallactic angle
**     *pad        double          "      "   velocity
**     *padd       double          "      "   acceleration
**
**  Notes:
**
**  1)  Natural units are used throughout.  HA, DEC, PHI, AZ, EL
**      and ZD are in radians.  The velocities and accelerations
**      assume constant declination and constant rate of change of
**      hour angle (as for tracking a star);  the units of AZD, ELD
**      and PAD are radians per radian of HA, while the units of AZDD,
**      ELDD and PADD are radians per radian of HA squared.  To
**      convert into practical degree- and second-based units:
**
**        angles * 360/2pi -> degrees
**        velocities * (2pi/86400)*(360/2pi) -> degree/sec
**        accelerations * ((2pi/86400)**2)*(360/2pi) -> degree/sec/sec
**
**      Note that the seconds here are sidereal rather than SI.  One
**      sidereal second is about 0.99727 SI seconds.
**
**      The velocity and acceleration factors assume the sidereal
**      tracking case.  Their respective numerical values are (exactly)
**      1/240 and (approximately) 1/3300236.9.
**
**  2)  Azimuth is returned in the range 0-2pi;  north is zero,
**      and east is +pi/2.  Elevation and parallactic angle are
**      returned in the range +/-pi.  Parallactic angle is +ve for
**      a star west of the meridian and is the angle NP-star-zenith.
**
**  3)  The latitude is geodetic as opposed to geocentric.  The
**      hour angle and declination are topocentric.  Refraction and
**      deficiencies in the telescope mounting are ignored.  The
**      purpose of the function is to give the general form of the
**      quantities.  The details of a real telescope could profoundly
**      change the results, especially close to the zenith.
**
**  4)  No range checking of arguments is carried out.
**
**  5)  In applications which involve many such calculations, rather
**      than calling the present function it will be more efficient to
**      use inline code, having previously computed fixed terms such
**      as sine and cosine of latitude, and (for tracking a star)
**      sine and cosine of declination.
**
**  Defined in slamac.h:  DPI, D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAmp ( double ra, double da, double date, double eq,
              double *rm, double *dm )
/*
**  - - - - - - -
**   s l a A m p
**  - - - - - - -
**
**  Convert star RA,Dec from geocentric apparent to mean place.
**
**  The mean coordinate system is the post IAU 1976 system,
**  loosely called FK5.
**
**  Given:
**     ra,da     double    apparent RA,Dec (radians)
**     date      double    TDB for apparent place (JD-2400000.5)
**     eq        double    equinox:  Julian epoch of mean place
**
**  Returned:
**     rm,dm     double*   mean RA,Dec (radians)
**
**  References:
**     1984 Astronomical Almanac, pp B39-B41.
**     (also Lederle & Schwan, Astron. Astrophys. 134, 1-6, 1984)
**
**  Notes:
**
**  1)  The distinction between the required TDB and TT is always
**      negligible.  Moreover, for all but the most critical
**      applications UTC is adequate.
**
**  2)  Iterative techniques are used for the aberration and light
**      deflection corrections so that the functions slaAmp (or
**      slaAmpqk) and slaMap (or slaMapqk) are accurate inverses;
**      even at the edge of the Sun's disc the discrepancy is only
**      about 1 nanoarcsecond.
**
**  3)  Where multiple apparent places are to be converted to mean
**      places, for a fixed date and equinox, it is more efficient to
**      use the slaMappa function to compute the required parameters
**      once, followed by one call to slaAmpqk per star.
**
**  4)  The accuracy is sub-milliarcsecond, limited by the
**      precession-nutation model (IAU 1976 precession, Shirai &
**      Fukushima 2001 forced nutation and precession corrections).
**
**  5)  The accuracy is further limited by the function slaEvp, called
**      by slaMappa, which computes the Earth position and velocity
**      using the methods of Stumpff.  The maximum error is about
**      0.3 mas.
**
**  Called:  slaMappa, slaAmpqk
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
**
*/


void slaAmpqk ( double ra, double da, double amprms[21],
                double *rm, double *dm )
/*
**  - - - - - - - - -
**   s l a A m p q k
**  - - - - - - - - -
**
**  Convert star RA,Dec from geocentric apparent to mean place.
**
**  The mean coordinate system is the post IAU 1976 system,
**  loosely called FK5.
**
**  Use of this function is appropriate when efficiency is important
**  and where many star positions are all to be transformed for
**  one epoch and equinox.  The star-independent parameters can be
**  obtained by calling the slaMappa function.
**
**  Given:
**     ra       double      apparent RA (radians)
**     da       double      apparent Dec (radians)
**
**     amprms   double[21]  star-independent mean-to-apparent parameters:
**
**       (0)      time interval for proper motion (Julian years)
**       (1-3)    barycentric position of the Earth (AU)
**       (4-6)    heliocentric direction of the Earth (unit vector)
**       (7)      (grav rad Sun)*2/(Sun-Earth distance)
**       (8-10)   abv: barycentric Earth velocity in units of c
**       (11)     sqrt(1-v*v) where v=modulus(abv)
**       (12-20)  precession/nutation (3,3) matrix
**
**  Returned:
**     *rm      double      mean RA (radians)
**     *dm      double      mean Dec (radians)
**
**  References:
**     1984 Astronomical Almanac, pp B39-B41.
**     (also Lederle & Schwan, Astron. Astrophys. 134, 1-6, 1984)
**
**  Note:
**
**     Iterative techniques are used for the aberration and
**     light deflection corrections so that the functions
**     slaAmp (or slaAmpqk) and slaMap (or slaMapqk) are
**     accurate inverses;  even at the edge of the Sun's disc
**     the discrepancy is only about 1 nanoarcsecond.
**
**  Called:  slaDcs2c, slaDimxv, slaDvdv, slaDvn, slaDcc2s,
**           slaDranrm
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAop ( double rap, double dap, double date, double dut,
              double elongm, double phim, double hm,
              double xp, double yp, double tdk, double pmb,
              double rh, double wl, double tlr,
              double *aob, double *zob,
              double *hob, double *dob,
              double *rob )
/*
**  - - - - - - -
**   s l a A o p
**  - - - - - - -
**
**  Apparent to observed place, for sources distant from the solar
**  system.
**
**  Given:
**     rap     double  geocentric apparent right ascension
**     dap     double  geocentric apparent declination
**     date    double  UTC date/time (Modified Julian Date, JD-2400000.5)
**     dut     double  delta UT:  UT1-UTC (UTC seconds)
**     elongm  double  mean longitude of the observer (radians, east +ve)
**     phim    double  mean geodetic latitude of the observer (radians)
**     hm      double  observer's height above sea level (metres)
**     xp      double  polar motion x-coordinate (radians)
**     yp      double  polar motion y-coordinate (radians)
**     tdk     double  local ambient temperature (K; std=273.15)
**     pmb     double  local atmospheric pressure (mb; std=1013.25)
**     rh      double  local relative humidity (in the range 0.0-1.0)
**     wl      double  effective wavelength (micron, e.g. 0.55)
**     tlr     double  tropospheric lapse rate (K/metre, e.g. 0.0065)
**
**  Returned:
**     aob     double  observed azimuth (radians: N=0,E=90)
**     zob     double  observed zenith distance (radians)
**     hob     double  observed Hour Angle (radians)
**     dob     double  observed Declination (radians)
**     rob     double  observed Right Ascension (radians)
**
**  Notes:
**
**   1)  This function returns zenith distance rather than elevation
**       in order to reflect the fact that no allowance is made for
**       depression of the horizon.
**
**   2)  The accuracy of the result is limited by the corrections for
**       refraction.  Providing the meteorological parameters are
**       known accurately and there are no gross local effects, the
**       predicted observed RA,Dec should be within about 0.1 arcsec
**       for a zenith distance of less than 70 degrees.  Even at a
**       topocentric zenith distance of 90 degrees, the accuracy in
**       elevation should be better than 1 arcmin;  useful results
**       are available for a further 3 degrees, beyond which the
**       slaRefro function returns a fixed value of the refraction.
**       The complementary functions slaAop (or slaAopqk) and slaOap
**       (or slaOapqk) are self-consistent to better than 1 micro-
**       arcsecond all over the celestial sphere.
**
**   3)  It is advisable to take great care with units, as even
**       unlikely values of the input parameters are accepted and
**       processed in accordance with the models used.
**
**   4)  "Apparent" place means the geocentric apparent right ascension
**       and declination, which is obtained from a catalogue mean place
**       by allowing for space motion, parallax, the Sun's gravitational
**       lens effect, annual aberration and precession-nutation.  For
**       star positions in the FK5 system (i.e. J2000), these effects
**       can be applied by means of the slaMap etc. functions.  Starting
**       from other mean place systems, additional transformations will
**       be needed;  for example, FK4 (i.e. B1950) mean places would
**       first have to be converted to FK5, which can be done with the
**       slaFk425 etc. functions.
**
**   5)  "Observed" Az,El means the position that would be seen by a
**       perfect theodolite located at the observer.  This is obtained
**       from the geocentric apparent RA,Dec by allowing for Earth
**       orientation and diurnal aberration, rotating from equator
**       to horizon coordinates, and then adjusting for refraction.
**       The HA,Dec is obtained by rotating back into equatorial
**       coordinates, using the geodetic latitude corrected for polar
**       motion, and is the position that would be seen by a perfect
**       equatorial located at the observer and with its polar axis
**       aligned to the Earth's axis of rotation (n.b. not to the
**       refracted pole).  Finally, the RA is obtained by subtracting
**       the HA from the local apparent ST.
**
**   6)  To predict the required setting of a real telescope, the
**       observed place produced by this function would have to be
**       adjusted for the tilt of the azimuth or polar axis of the
**       mounting (with appropriate corrections for mount flexures),
**       for non-perpendicularity between the mounting axes, for the
**       position of the rotator axis and the pointing axis relative
**       to it, for tube flexure, for gear and encoder errors, and
**       finally for encoder zero points.  Some telescopes would, of
**       course, exhibit other properties which would need to be
**       accounted for at the appropriate point in the sequence.
**
**   7)  This function takes time to execute, due mainly to the
**       rigorous integration used to evaluate the refraction.
**       For processing multiple stars for one location and time,
**       call slaAoppa once followed by one call per star to slaAopqk.
**       Where a range of times within a limited period of a few hours
**       is involved, and the highest precision is not required, call
**       slaAoppa once, followed by a call to slaAoppat each time the
**       time changes, followed by one call per star to slaAopqk.
**
**   8)  The date argument is UTC expressed as an MJD.  This is,
**       strictly speaking, wrong, because of leap seconds.  However,
**       as long as the delta UT and the UTC are consistent there
**       are no difficulties, except during a leap second.  In this
**       case, the start of the 61st second of the final minute should
**       begin a new MJD day and the old pre-leap delta UT should
**       continue to be used.  As the 61st second completes, the MJD
**       should revert to the start of the day as, simultaneously,
**       the delta UTC changes by one second to its post-leap new value.
**
**   9)  The delta UT (UT1-UTC) is tabulated in IERS circulars and
**       elsewhere.  It increases by exactly one second at the end of
**       each UTC leap second, introduced in order to keep delta UT
**       within +/- 0.9 seconds.
**
**  10)  IMPORTANT -- TAKE CARE WITH THE LONGITUDE SIGN CONVENTION.
**       The longitude required by the present function is east-
**       positive, in accordance with geographical convention (and
**       right-handed).  In particular, note that the longitudes
**       returned by the slaObs function are west-positive, following
**       astronomical usage, and must be reversed in sign before use in
**       the present function.
**
**  11)  The polar coordinates xp,yp can be obtained from IERS
**       circulars and equivalent publications.  The maximum amplitude
**       is about 0.3 arcseconds.  If xp,yp values are unavailable,
**       use xp=yp=0.0.  See page B60 of the 1988 Astronomical Almanac
**       for a definition of the two angles.
**
**  12)  The height above sea level of the observing station, hm,
**       can be obtained from the Astronomical Almanac (Section J
**       in the 1988 edition), or via the function slaObs.  If p,
**       the pressure in millibars, is available, an adequate
**       estimate of hm can be obtained from the expression
**
**             hm = -29.3 * tsl * log ( p / 1013.25 );
**
**       where tsl is the approximate sea-level air temperature in K
**       (See Astrophysical Quantities, C.W.Allen, 3rd edition, section
**       52).  Similarly, if the pressure p is not known, it can be
**       estimated from the height of the observing station, hm, as
**       follows:
**
**             p = 1013.25 * exp ( -hm / ( 29.3 * tsl ) );
**
**       Note, however, that the refraction is nearly proportional to
**       the pressure and that an accurate p value is important for
**       precise work.
**
**  13)  The azimuths etc produced by the present function are with
**       respect to the celestial pole.  Corrections to the terrestrial
**       pole can be computed using slaPolmo.
**
**  Called:  slaAoppa, slaAopqk
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAoppa ( double date, double dut, double elongm, double phim,
                double hm, double xp, double yp, double tdk,
                double pmb, double rh, double wl, double tlr,
                double aoprms[14] )
/*
**  - - - - - - - - -
**   s l a A o p p a
**  - - - - - - - - -
**
**  Precompute apparent to observed place parameters required by
**  slaAopqk and slaOapqk.
**
**  Given:
**     date   d      UTC date/time (Modified Julian Date, JD-2400000.5)
**     dut    d      delta UT:  UT1-UTC (UTC seconds)
**     elongm d      mean longitude of the observer (radians, east +ve)
**     phim   d      mean geodetic latitude of the observer (radians)
**     hm     d      observer's height above sea level (metres)
**     xp     d      polar motion x-coordinate (radians)
**     yp     d      polar motion y-coordinate (radians)
**     tdk    d      local ambient temperature (K; std=273.15)
**     pmb    d      local atmospheric pressure (mb; std=1013.25)
**     rh     d      local relative humidity (in the range 0.0-1.0)
**     wl     d      effective wavelength (micron, e.g. 0.55)
**     tlr    d      tropospheric lapse rate (K/metre, e.g. 0.0065)
**
**  Returned:
**     aoprms d[14]  star-independent apparent-to-observed parameters:
**
**       (0)      geodetic latitude (radians)
**       (1,2)    sine and cosine of geodetic latitude
**       (3)      magnitude of diurnal aberration vector
**       (4)      height (hm)
**       (5)      ambient temperature (tdk)
**       (6)      pressure (pmb)
**       (7)      relative humidity (rh)
**       (8)      wavelength (wl)
**       (9)      lapse rate (tlr)
**       (10,11)  refraction constants A and B (radians)
**       (12)     longitude + eqn of equinoxes + sidereal DUT (radians)
**       (13)     local apparent sidereal time (radians)
**
**  Notes:
**
**   1)  It is advisable to take great care with units, as even
**       unlikely values of the input parameters are accepted and
**       processed in accordance with the models used.
**
**   2)  The date argument is UTC expressed as an MJD.  This is,
**       strictly speaking, improper, because of leap seconds.  However,
**       as long as the delta UT and the UTC are consistent there
**       are no difficulties, except during a leap second.  In this
**       case, the start of the 61st second of the final minute should
**       begin a new MJD day and the old pre-leap delta UT should
**       continue to be used.  As the 61st second completes, the MJD
**       should revert to the start of the day as, simultaneously,
**       the delta UTC changes by one second to its post-leap new value.
**
**   3)  The delta UT (UT1-UTC) is tabulated in IERS circulars and
**       elsewhere.  It increases by exactly one second at the end of
**       each UTC leap second, introduced in order to keep delta UT
**       within +/- 0.9 seconds.
**
**   4)  IMPORTANT -- TAKE CARE WITH THE LONGITUDE SIGN CONVENTION.
**       The longitude required by the present function is
**       east-positive in accordance with geographical convention (and
**       right-handed).  In particular, note that the longitudes
**       returned by the slaObs function are west-positive, following
**       astronomical usage, and must be reversed in sign before use in
**       the present function.
**
**   5)  The polar coordinates xp,yp can be obtained from IERS
**       circulars and equivalent publications.  The maximum amplitude
**       is about 0.3 arcseconds.  If xp,yp values are unavailable,
**       use xp=yp=0.0.  See page B60 of the 1988 Astronomical Almanac
**       for a definition of the two angles.
**
**   6)  The height above sea level of the observing station, hm,
**       can be obtained from the Astronomical Almanac (Section J
**       in the 1988 edition), or via the function slaObs.  If p,
**       the pressure in millibars, is available, an adequate
**       estimate of hm can be obtained from the expression
**
**             hm = -29.3 * tsl * log ( p / 1013.25 );
**
**       where tsl is the approximate sea-level air temperature in K
**       (See Astrophysical Quantities, C.W.Allen, 3rd edition, section
**       52).  Similarly, if the pressure p is not known, it can be
**       estimated from the height of the observing station, hm, as
**       follows:
**
**             p = 1013.25 * exp ( -hm / ( 29.3 * tsl ) );
**
**       Note, however, that the refraction is nearly proportional to
**       the pressure and that an accurate p value is important for
**       precise work.
**
**   7)  Repeated, computationally-expensive, calls to slaAoppa for
**       times that are very close together can be avoided by calling
**       slaAoppa just once and then using slaAoppat for the subsequent
**       times.  Fresh calls to slaAoppa will be needed only when
**       changes in the equation of the equinoxes or the polar motion
**       have grown to unacceptable levels or when anything affecting
**       the refraction has changed.
**
**  Defined in slamac.h:  D2PI, DS2R
**
**  Called:  slaGeoc, slaRefco, slaEqeqx, slaAoppat
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAoppat ( double date, double aoprms[14] )
/*
**  - - - - - - - - - -
**   s l a A o p p a t
**  - - - - - - - - - -
**
**  Recompute the sidereal time in the apparent to observed place
**  star-independent parameter block.
**
**  Given:
**     date   double      UTC date/time (Modified Julian Date, JD-2400000.5)
**                        (see slaAoppa source for comments on leap seconds)
**     aoprms double[14]  star-independent apparent-to-observed parameters
**
**       (0-11)   not required
**       (12)     longitude + eqn of equinoxes + sidereal dut
**       (13)     not required
**
**  Returned:
**     aoprms double[14]  star-independent apparent-to-observed parameters:
**
**       (0-12)   not changed
**       (13)     local apparent sidereal time (radians)
**
**  For more information, see slaAoppa.
**
**  Called:  slaGmst
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAopqk ( double rap, double dap, double aoprms[14],
                double *aob, double *zob, double *hob,
                double *dob, double *rob )
/*
**  - - - - - - - - -
**   s l a A o p q k
**  - - - - - - - - -
**
**  Quick apparent to observed place (but see note 8, below, for
**  remarks about speed).
**
**  Given:
**     rap    double      geocentric apparent right ascension
**     dap    double      geocentric apparent declination
**     aoprms double[14]  star-independent apparent-to-observed parameters:
**
**       (0)      geodetic latitude (radians)
**       (1,2)    sine and cosine of geodetic latitude
**       (3)      magnitude of diurnal aberration vector
**       (4)      height (hm)
**       (5)      ambient temperature (t)
**       (6)      pressure (p)
**       (7)      relative humidity (rh)
**       (8)      wavelength (wl)
**       (9)      lapse rate (tlr)
**       (10,11)  refraction constants A and B (radians)
**       (12)     longitude + eqn of equinoxes + sidereal DUT (radians)
**       (13)     local apparent sidereal time (radians)
**
**  Returned:
**     *aob    double      observed azimuth (radians: N=0,E=90)
**     *zob    double      observed zenith distance (radians)
**     *hob    double      observed hour angle (radians)
**     *dob    double      observed declination (radians)
**     *rob    double      observed right ascension (radians)
**
**  Notes:
**
**   1)  This function returns zenith distance rather than elevation
**       in order to reflect the fact that no allowance is made for
**       depression of the horizon.
**
**   2)  The accuracy of the result is limited by the corrections for
**       refraction.  Providing the meteorological parameters are
**       known accurately and there are no gross local effects, the
**       observed RA,Dec predicted by this function should be within
**       about 0.1 arcsec for a zenith distance of less than 70 degrees.
**       Even at a topocentric zenith distance of 90 degrees, the
**       accuracy in elevation should be better than 1 arcmin;  useful
**       results are available for a further 3 degrees, beyond which
**       the slaRefro function returns a fixed value of the refraction.
**       The complementary functions slaAop (or slaAopqk) and slaOap
**       (or slaOapqk) are self-consistent to better than 1 micro-
**       arcsecond all over the celestial sphere.
**
**   3)  It is advisable to take great care with units, as even
**       unlikely values of the input parameters are accepted and
**       processed in accordance with the models used.
**
**   4)  "Apparent" place means the geocentric apparent right ascension
**       and declination, which is obtained from a catalogue mean place
**       by allowing for space motion, parallax, the Sun's gravitational
**       lens effect, annual aberration and precession-nutation.  For
**       star positions in the FK5 system (i.e. J2000), these effects
**       can be applied by means of the slaMap etc. functions.  Starting
**       from other mean place systems, additional transformations will
**       be needed;  for example, FK4 (i.e. B1950) mean places would
**       first have to be converted to FK5, which can be done with the
**       slaFk425 etc. functions.
**
**   5)  "Observed" Az,El means the position that would be seen by a
**       perfect theodolite located at the observer.  This is obtained
**       from the geocentric apparent RA,Dec by allowing for Earth
**       orientation and diurnal aberration, rotating from equator
**       to horizon coordinates, and then adjusting for refraction.
**       The HA,Dec is obtained by rotating back into equatorial
**       coordinates, using the geodetic latitude corrected for polar
**       motion, and is the position that would be seen by a perfect
**       equatorial located at the observer and with its polar axis
**       aligned to the Earth's axis of rotation (n.b. not to the
**       refracted pole).  Finally, the RA is obtained by subtracting
**       the HA from the local apparent ST.
**
**   6)  To predict the required setting of a real telescope, the
**       observed place produced by this function would have to be
**       adjusted for the tilt of the azimuth or polar axis of the
**       mounting (with appropriate corrections for mount flexures),
**       for non-perpendicularity between the mounting axes, for the
**       position of the rotator axis and the pointing axis relative
**       to it, for tube flexure, for gear and encoder errors, and
**       finally for encoder zero points.  Some telescopes would, of
**       course, exhibit other properties which would need to be
**       accounted for at the appropriate point in the sequence.
**
**   7)  The star-independent apparent-to-observed-place parameters
**       in aoprms may be computed by means of the slaAoppa function.
**       If nothing has changed significantly except the time, the
**       slaAoppat function may be used to perform the requisite
**       partial recomputation of aoprms.
**
**   8)  At zenith distances beyond about 76 degrees, the need for
**       special care with the corrections for refraction causes a
**       marked increase in execution time.  Moreover, the effect
**       gets worse with increasing zenith distance.  Adroit
**       programming in the calling application may allow the
**       problem to be reduced.  Prepare an alternative aoprms array,
**       computed for zero air-pressure;  this will disable the
**       refraction corrections and cause rapid execution.  Using
**       this aoprms array, a preliminary call to the present function
**       will, depending on the application, produce a rough position
**       which may be enough to establish whether the full, slow
**       calculation (using the real aoprms array) is worthwhile.
**       For example, there would be no need for the full calculation
**       if the preliminary call had already established that the
**       source was well below the elevation limits for a particular
**       telescope.
**
**   9)  The azimuths etc produced by the present function are with
**       respect to the celestial pole.  Corrections to the terrestrial
**       pole can be computed using slaPolmo.
**
**  Called:  slaDcs2c, slaRefz, slaRefro, slaDcc2s, slaDranrm
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAtmdsp ( double tdk, double pmb, double rh, double wl1,
                 double a1, double b1, double wl2, double *a2, double *b2 )
/*
**  - - - - - - - - - -
**   s l a A t m d s p
**  - - - - - - - - - -
**
**  Apply atmospheric-dispersion adjustments to refraction coefficients.
**
**  Given:
**     tdk   double   ambient temperature, K
**     pmb   double   ambient pressure, millibars
**     rh    double   ambient relative humidity, 0-1
**     wl1   double   reference wavelength, micrometre (0.4 recommended)
**     a1    double   refraction coefficient A for wavelength wl1 (radians)
**     b1    double   refraction coefficient B for wavelength wl1 (radians)
**     wl2   double   wavelength for which adjusted A,B required
**
**  Returned:
**     *a2   double   refraction coefficient A for wavelength wl2 (radians)
**     *b2   double   refraction coefficient B for wavelength wl2 (radians)
**
**  Notes:
**
**  1  To use this function, first call slaRefco specifying wl1 as the
**     wavelength.  This yields refraction coefficients a1,b1, correct
**     for that wavelength.  Subsequently, calls to slaAtmdsp specifying
**     different wavelengths will produce new, slightly adjusted
**     refraction coefficients which apply to the specified wavelength.
**
**  2  Most of the atmospheric dispersion happens between 0.7 micrometre
**     and the UV atmospheric cutoff, and the effect increases strongly
**     towards the UV end.  For this reason a blue reference wavelength
**     is recommended, for example 0.4 micrometres.
**
**  3  The accuracy, for this set of conditions:
**
**        height above sea level    2000 m
**                      latitude    29 deg
**                      pressure    793 mb
**                   temperature    17 degC
**                      humidity    50%
**                    lapse rate    0.0065 degC/m
**          reference wavelength    0.4 micrometre
**                star elevation    15 deg
**
**     is about 2.5 mas RMS between 0.3 and 1.0 micrometres, and stays
**     within 4 mas for the whole range longward of 0.3 micrometres
**     (compared with a total dispersion from 0.3 to 20.0 micrometres
**     of about 11 arcsec).  These errors are typical for ordinary
**     conditions and the given elevation;  in extreme conditions values
**     a few times this size may occur, while at higher elevations the
**     errors become much smaller.
**
**  4  If either wavelength exceeds 100 micrometres, the radio case
**     is assumed and the returned refraction coefficients are the
**     same as the given ones.  Note that radio refraction coefficients
**     cannot be turned into optical values using this function, nor
**     vice versa.
**
**  5  The algorithm consists of calculation of the refractivity of the
**     air at the observer for the two wavelengths, using the methods
**     of the slaRefro function, and then scaling of the two refraction
**     coefficients according to classical refraction theory.  This
**     amounts to scaling the A coefficient in proportion to (n-1) and
**     the B coefficient almost in the same ratio (see R.M.Green,
**     "Spherical Astronomy", Cambridge University Press, 1985).
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaAv2m ( float axvec[3], float rmat[3][3] )
/*
**  - - - - - - - -
**   s l a A v 2 m
**  - - - - - - - -
**
**  Form the rotation matrix corresponding to a given axial vector.
**
**  (single precision)
**
**  A rotation matrix describes a rotation about some arbitrary axis,
**  called the Euler axis.  The "axial vector" supplied to this function
**  has the same direction as the Euler axis, and its magnitude is the
**  amount of rotation in radians.
**
**  Given:
**    axvec  float[3]     axial vector (radians)
**
**  Returned:
**    rmat   float[3][3]  rotation matrix
**
**  If axvec is null, the unit matrix is returned.
**
**  The reference frame rotates clockwise as seen looking along
**  the axial vector from the origin.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaBear ( float a1, float b1, float a2, float b2 )
/*
**  - - - - - - - -
**   s l a B e a r
**  - - - - - - - -
**
**  Bearing (position angle) of one point on a sphere relative
**  to another.
**
**  (single precision)
**
**  Given:
**     a1,b1    float    spherical coordinates of one point
**     a2,b2    float    spherical coordinates of the other point
**
**  (The spherical coordinates are RA,Dec, Long,Lat etc, in radians.)
**
**  The result is the bearing (position angle), in radians, of point
**  a2,b2 as seen from point a1,b1.  It is in the range +/- pi.  The
**  sense is such that if a2,b2 is a small distance east of a1,b1,
**  the bearing is about +pi/2.  Zero is returned if the two points
**  are coincident.
**
**  If either b-coordinate is outside the range +/- pi/2, the
**  result may correspond to "the long way round".
**
**  The function slaPav performs an equivalent function except
**  that the points are specified in the form of Cartesian unit
**  vectors.
**
**  Called:  slaDbear
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaC2i ( double rc, double dc, double pr, double pd,
              double px, double rv, double date, double dx, double dy,
              double *ri, double *di )
/*
**  - - - - - - -
**   s l a C 2 i
**  - - - - - - -
**
**  Transform ICRS star data, epoch J2000, to RA,Dec in the celestial
**  intermediate reference system.
**
**  Given:
**     rc,dc  double    ICRS RA,Dec at J2000 (radians)
**     pr,pd  double    proper motions:  RA,Dec changes per Julian year
**     px     double    parallax (arcsec)
**     rv     double    radial velocity (km/sec, +ve if receding)
**     date   double    TDB for CIRS place (JD-2400000.5)
**     dx,dy  double    corrections to IAU CIP X,Y (radians)
**
**  Returned:
**     ri,di  double*   CIRS RA,Dec (radians)
**
**  Notes:
**
**  1)  Star data for an epoch other than J2000 (for example from the
**      Hipparcos catalog) will require a preliminary call to slaPm
**      before use.
**
**  2)  The distinction between the required TDB and TT is always
**      negligible.  Moreover, for all but the most critical
**      applications, UTC is adequate.
**
**  3)  The proper motions in RA are dRA/dt rather than cos(Dec)*dRA/dt.
**
**  4)  This function may be wasteful for some applications because it
**      recomputes the Earth position/velocity and the bias-precession-
**      nutation matrix each time, and because it allows for parallax
**      and proper motion.  Where multiple transformations are to be
**      carried out for one date, a faster method is to call the
**      slaC2ipa function once and then either the slaC2iqk function
**      (which includes parallax and proper motion) or slaC2iqkz (which
**      assumes zero parallax and proper motion).
**
**  5)  The accuracy is sub-milliarcsecond, limited by the precession-
**      nutation information (IAU 2006 model plus the CIP corrections,
**      which are obtained from IERS bulletins).
**
**  6)  The accuracy is in principle further limited by the function
**      slaEpv, called by slaC2ipa, which computes the Earth position
**      and velocity.  The maximum error arising from this source is
**      less than 5 microarcseconds.
**
**  Called:  slaC2ipa, slaC2iqk
**
**  Last revision:   17 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaC2ipa ( double date, double dx, double dy,
                CIpars *ciprms, double *eo )
/*
**  - - - - - - - - -
**   s l a C 2 i p a
**  - - - - - - - - -
**
**  For a geocentric observer, compute star-independent parameters in
**  preparation for conversions between ICRS star data CIRS RA,Dec.
**
**  The parameters produced by this function are required in the
**  parallax, light deflection, aberration and precession-nutation parts
**  of the ICRS/CIRS transformations.
**
**  Given:
**     date    double     TDB (JD-2400000.5)
**     dx,dy   double     corrections to IAU CIP X,Y (radians)
**
**  Returned:
**     ciprms  CIpars*    star-independent ICRS-to-CIRS parameters:
**      pmt        double    time interval for proper motion (Jyears)
**      eb[3]      double    SSB to Earth (AU)
**      ehn[3]     double    Sun to Earth unit vector
**      gr2e       double    (grav rad Sun)*2/(Sun-Earth distance)
**      abv[3]     double    barycentric Earth velocity in units of c
**      ab1        double    sqrt(1-v**2) where v=modulus(abv)
**      bpn[3][3]  double    bias-precession-nutation matrix
**     eo      double*    equation of the origins (ERA-GST)
**
**  Notes:
**
**  1)  For date, the distinction between the required TDB and TT is
**      always negligible.  Moreover, for all but the most critical
**      applications UTC is adequate.
**
**  2)  The vectors ciprms->eb and ciprms->ehn are in the BCRS.
**
**  3)  The parameters ciprms produced by this function are used by
**      slaC2iqk, slaC2iqkz and slaI2cqk.  The bias-precession-
**      nutation portion can be suppressed using slaC2ipad, allowing
**      transformations to and from GCRS instead of CIRS.
**
**  4)  The accuracy is sub-milliarcsecond, limited by the precession-
**      nutation information (IAU 2006 model plus the CIP corrections,
**      which are obtained from IERS bulletins).
**
**  5)  The accuracy is in principle further limited by the function
**      slaEpv, which computes the Earth position and velocity.  The
**      maximum error arising from this source is less than
**      5 microarcseconds.
**
**  Called:  slaC2ipas
**
**  Last revision:   18 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaC2ipad ( CIpars *ciprms )
/*
**  - - - - - - - - - -
**   s l a C 2 i p a d
**  - - - - - - - - - -
**
**  In the ICRS to CIRS star-independent parameters, disable bias-
**  precession-nutation.  Subsequent calls to slaC2iqk will consequently
**  produce GCRS coordinates rather than CIRS.
**
**  Given:
**     ciprms CIpars*   star-independent ICRS-to-CIRS parameters
**      pmt        double    time interval for proper motion (Jyears)
**      eb[3]      double    SSB to Earth (AU)
**      ehn[3]     double    Sun to Earth unit vector
**      gr2e       double    (grav rad Sun)*2/(Sun-Earth distance)
**      abv[3]     double    barycentric Earth velocity in units of c
**      ab1        double    sqrt(1-v**2) where v=modulus(abv)
**      bpn[3][3]  double    bias-precession-nutation matrix
**
**  Returned:
**     ciprms CIpars*   star-independent ICRS-to-GCRS parameters:
**      pmt        double    unchanged
**      eb[3]      double    unchanged
**      ehn[3]     double    unchanged
**      gr2e       double    unchanged
**      abv[3]     double    unchanged
**      ab1        double    unchanged
**      bpn[3][3]  double    identity matrix
**
**  Last revision:   17 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaC2ipas ( double date, double pv[2][3], double dx, double dy,
                 CIpars *ciprms, double *eo )
/*
**  - - - - - - - - - -
**   s l a C 2 i p a s
**  - - - - - - - - - -
**
**  For an observer not necessarily coincident with the geocenter,
**  compute star-independent parameters in preparation for
**  transformations between ICRS star data and CIRS RA,Dec.
**
**  The parameters produced by this function are required in the
**  parallax, light deflection, aberration and precession-nutation parts
**  of the ICRS/CIRS transformations.
**
**  Given:
**     date    double       TDB (JD-2400000.5)
**     pv      double[2][3] observer's geocentric position and velocity
**     dx      double       CIP X-correction (radians)
**     dy      double       CIP Y-correction (radians)
**
**  Returned:
**     ciprms  CIpars*      star-independent ICRS-to-CIRS parameters:
**      pmt        double    time interval for proper motion (Jyears)
**      eb[3]      double    SSB to Earth (AU)
**      ehn[3]     double    Sun to Earth unit vector
**      gr2e       double    (grav rad Sun)*2/(Sun-Earth distance)
**      abv[3]     double    observer's barycentric velocity / c
**      ab1        double    sqrt(1-v**2) where v=modulus(abv)
**      bpn[3][3]  double    bias-precession-nutation matrix
**     eo      double*      equation of the origins (ERA-GST)
**
**  Notes:
**
**  1)  For date, the distinction between the required TDB and TT is
**      always negligible.  Moreover, for all but the most critical
**      applications UTC is adequate.
**
**  2)  The vectors ciprms->eb and ciprms->ehn are in the BCRS.
**
**  3)  The parameters ciprms produced by this function are used by
**      slaC2iqk, slaC2iqkz and slaI2cqk.  The bias-precession-
**      nutation portion can be suppressed using slaC2ipad, allowing
**      transformations to and from GCRS instead of CIRS.
**
**  4)  The accuracy is sub-milliarcsecond, limited by the precession-
**      nutation information (IAU 2006 model plus the CIP corrections,
**      which are obtained from IERS bulletins).
**
**  5)  The accuracy is in principle further limited by the function
**      slaEpv00, called by slaC2ipa, which computes the Earth position
**      and velocity.  The maximum error arising from this source is
**      less than 5 microarcseconds.
**
**  6)  The observer's position and velocity pv are in GCRS coordinates
**      and in units of km and km/s.
**
**  Called:  slaEpj, slaEpv, slaDvn, slaPfw, slaNu, slaFw2m, slaG2ixys,
**           slaS
**
**  Last revision:   17 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaC2iqk ( double rc, double dc, double pr, double pd,
                double px, double rv, CIpars *ciprms,
                double *ri, double *di )
/*
**  - - - - - - - - -
**   s l a C 2 i q k
**  - - - - - - - - -
**
**  Quick ICRS place, epoch J2000, to geocentric CIRS, given the star-
**  independent parameters.
**
**  Use of this function is appropriate when efficiency is important and
**  where many star positions are to be transformed for one date.  The
**  star-independent parameters can be obtained by calling the slaC2ipa
**  function.
**
**  If the parallax and proper motions are zero the slaC2iqkz function
**  can be used instead.
**
**  Given:
**     rc,dc   double    ICRS RA,Dec at J2000 (radians)
**     pr,pd   double    proper motions:  RA,Dec changes per Julian year
**     px      double    parallax (arcsec)
**     rv      double    radial velocity (km/sec, +ve if receding)
**     ciprms  CIpars*   star-independent ICRS-to-CIRS parameters:
**      pmt        double    time interval for proper motion (Jyears)
**      eb[3]      double    SSB to Earth (AU)
**      ehn[3]     double    Sun to Earth unit vector
**      gr2e       double    (grav rad Sun)*2/(Sun-Earth distance)
**      abv[3]     double    barycentric Earth velocity in units of c
**      ab1        double    sqrt(1-v**2) where v=modulus(abv)
**      bpn[3][3]  double    bias-precession-nutation matrix
**
**  Returned:
**     ri,di  double*   CIRS RA,Dec (radians)
**
**  Notes:
**
**  1)  The vectors ciprms->eb and ciprms->ehn are in the BCRS.
**
**  2)  Strictly speaking, the function is not valid for solar-system
**      sources, though the error will usually be extremely small.
**      However, to prevent gross errors in the case where the
**      position of the Sun is specified, the gravitational
**      deflection term is restrained within about 920 arcsec of the
**      center of the Sun's disc.  The term has a maximum value of
**      about 1.85 arcsec at this radius, and decreases to zero as
**      the centre of the disc is approached.
**
**  3)  See the slaC2i function for further details.
**
**  Reference:
**     Explanatory Supplement to the Astronomical Ephemeris, Chapter 3.
**
**  Called:  slaDcs2c, slaDvdv, slaDmxv, slaDcc2s, slaDranrm
**
**  Defined in slamac.h:  DAS2R, gmax
**
**  Last revision:   18 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaC2iqkz  ( double rc, double dc, CIpars *ciprms,
                  double *ri, double *di )
/*
**  - - - - - - - - - -
**   s l a C 2 i q k z
**  - - - - - - - - - -
**
**  Quick ICRS RA,Dec, epoch J2000, to CIRS, given the star-independent
**  parameters, and assuming zero parallax and proper motion.
**
**  Use of this function is appropriate when efficiency is important and
**  where many star positions, all with parallax and proper motion either
**  zero or already allowed for, are to be transformed for one date.  The
**  star-independent parameters can be obtained by calling the slaC2ipa
**  function.
**
**  The corresponding function for the case of non-zero parallax and
**  proper motion is slaC2iqk.
**
**  Given:
**     rc,dc  double    ICRS RA,Dec at J2000 (radians)
**     ciprms CIpars*   star-independent ICRS-to-CIRS parameters:
**      pmt        double    time interval for proper motion (Jyears)
**      eb[3]      double    SSB to Earth (AU)
**      ehn[3]     double    Sun to Earth unit vector
**      gr2e       double    (grav rad Sun)*2/(Sun-Earth distance)
**      abv[3]     double    barycentric Earth velocity in units of c
**      ab1        double    sqrt(1-v**2) where v=modulus(abv)
**      bpn[3][3]  double    bias-precession-nutation matrix
**
**  Returned:
**     ri,di  double*   CIRS RA,Dec (radians)
**
**  Notes:
**
**  1)  The vectors ciprms->eb and ciprms->ehn are in the BCRS.
**
**  2)  Strictly speaking, the function is not valid for solar-system
**      sources, though the error will usually be extremely small.
**      However, to prevent gross errors in the case where the
**      position of the Sun is specified, the gravitational
**      deflection term is restrained within about 920 arcsec of the
**      center of the Sun's disc.  The term has a maximum value of
**      about 1.85 arcsec at this radius, and decreases to zero as
**      the centre of the disc is approached.
**
**  Called:  slaDcs2c, slaDvdv, slaDmxv, slaDcc2s, slaDranrm
**
**  Last revision:   19 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCaf2r ( int ideg, int iamin, float asec, float *rad, int *j )
/*
**  - - - - - - - - -
**   s l a C a f 2 r
**  - - - - - - - - -
**
**  Convert degrees, arcminutes, arcseconds to radians.
**
**  (single precision)
**
**  Given:
**     ideg        int       degrees
**     iamin       int       arcminutes
**     asec        float     arcseconds
**
**  Returned:
**     *rad        float     angle in radians
**     *j          int       status:  0 = ok
**                                    1 = ideg outside range 0-359
**                                    2 = iamin outside range 0-59
**                                    3 = asec outside range 0-59.999...
**
**  Notes:
**     1)  The result is computed even if any of the range checks fail.
**
**     2)  The sign must be dealt with outside this function.
**
**  Called:  slaDaf2r
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCaldj ( int iy, int im, int id, double *djm, int *j )
/*
**  - - - - - - - - -
**   s l a C a l d j
**  - - - - - - - - -
**
**  Gregorian calendar to Modified Julian Date.
**
**  (Includes century default feature:  use slaCldj for years
**   before 100AD.)
**
**  Given:
**     iy,im,id   int      year, month, day in Gregorian calendar
**
**  Returned:
**     *djm       double   Modified Julian Date (JD-2400000.5) for 0 hrs
**     *j         int      status:
**                           0 = ok
**                           1 = bad year   (MJD not computed)
**                           2 = bad month  (MJD not computed)
**                           3 = bad day    (MJD computed)
**
**  Acceptable years are 00-49, interpreted as 2000-2049,
**                       50-99,     "       "  1950-1999,
**                       100 upwards, interpreted literally.
**
**  Called:  slaCldj
**
**  Last revision:   21 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCalyd ( int iy, int im, int id, int *ny, int *nd, int *j )
/*
**  - - - - - - - - -
**   s l a C a l y d
**  - - - - - - - - -
**
**  Gregorian calendar date to year and day in year (in a Julian
**  calendar aligned to the 20th/21st century Gregorian calendar).
**
**  (Includes century default feature:  use slaClyd for years
**   before 100AD.)
**
**  Given:
**     iy,im,id   int    year, month, day in Gregorian calendar
**                       (year may optionally omit the century)
**  Returned:
**     *ny        int    year (re-aligned Julian calendar)
**     *nd        int    day in year (1 = January 1st)
**     *j         int    status:
**                         0 = OK
**                         1 = bad year (before -4711)
**                         2 = bad month
**                         3 = bad day (but conversion performed)
**
**  Notes:
**
**  1  This function exists to support the low-accuracy functions
**     slaEarth, slaMoon and slaEcor.
**
**  2  Between 1900 March 1 and 2100 February 28 it returns answers
**     which are consistent with the ordinary Gregorian calendar.
**     Outside this range there will be a discrepancy which increases
**     by one day for every non-leap century year.
**
**  3  Years in the range 50-99 are interpreted as 1950-1999, and
**     years in the range 00-49 are interpreted as 2000-2049.
**
**  Called:  slaClyd
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCc2s ( float v[3], float *a, float *b )
/*
**  - - - - - - - -
**   s l a C c 2 s
**  - - - - - - - -
**
**  Cartesian to spherical coordinates (single precision)
**
**  Given:
**     v       float[3]   x,y,z vector
**
**  Returned:
**     *a,*b   float      spherical coordinates in radians
**
**  The spherical coordinates are longitude (+ve anticlockwise looking
**  from the +ve latitude pole) and latitude.  The Cartesian coordinates
**  are right handed, with the x axis at zero longitude and latitude,
**  and the z axis at the +ve latitude pole.
**
**  If v is null, zero a and b are returned.  At either pole, zero a is
**  returned.
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCc62s ( float v[6],
                float *a, float *b, float *r,
                float *ad, float *bd, float *rd )
/*
**  - - - - - - - - -
**   s l a C c 6 2 s
**  - - - - - - - - -
**
**  Conversion of position & velocity in Cartesian coordinates
**  to spherical coordinates.
**
**  (single precision)
**
**  Given:
**     v     float[6]   Cartesian position & velocity vector
**
**  Returned:
**     *a    float      longitude (radians)
**     *b    float      latitude (radians)
**     *r    float      radial coordinate
**     *ad   float      longitude derivative (radians per unit time)
**     *bd   float      latitude derivative (radians per unit time)
**     *rd   float      radial derivative
**
**  Last revision:   28 April 1996
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCd2tf ( int ndp, float days, char *sign, int ihmsf[4] )
/*
**  - - - - - - - - -
**   s l a C d 2 t f
**  - - - - - - - - -
**
**  Convert an interval in days into hours, minutes, seconds.
**
**  (single precision)
**
**  Given:
**     ndp       int      number of decimal places of seconds
**     days      float    interval in days
**
**  Returned:
**     sign      char*    '+' or '-'
**     ihmsf     int[4]   hours, minutes, seconds, fraction
**
**  Notes:
**
**  1  ndp less than zero is interpreted as zero.
**
**  2  The largest useful value for ndp is determined by the size of
**     days, the format of float floating-point numbers on the target
**     machine, and the risk of overflowing ihmsf[3].  On some
**     architectures, for days up to 1.0f, the available floating-
**     point precision corresponds roughly to ndp=3.  This is well below
**     the ultimate limit of ndp=9 set by the capacity of a typical
**     32-bit ihmsf[3].
**
**  3  The absolute value of days may exceed 1.0f.  In cases where it
**     does not, it is up to the caller to test for and handle the case
**     where days is very nearly 1.0f and rounds up to 24 hours, by
**     testing for ihmsf[0]=24 and setting ihmsf[0-3] to zero.
**
**  Called:  slaDd2tf
**
**  Last revision:   26 December 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCldj ( int iy, int im, int id, double *djm, int *j )
/*
**  - - - - - - - -
**   s l a C l d j
**  - - - - - - - -
**
**  Gregorian calendar to Modified Julian Date.
**
**  Given:
**     iy,im,id    int     year, month, day in Gregorian calendar
**
**  Returned:
**     *djm        double  Modified Julian Date (JD-2400000.5) for 0 hrs
**     *j          int     status:
**                           0 = OK
**                           1 = bad year   (MJD not computed)
**                           2 = bad month  (MJD not computed)
**                           3 = bad day    (MJD computed)
**
**  The year must be -4699 (i.e. 4700BC) or later.
**
**  The algorithm is adapted from Hatcher 1984 (QJRAS 25, 53-55).
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaClyd ( int iy, int im, int id, int *ny, int *nd, int *jstat )
/*
**  - - - - - - - -
**   s l a C l y d
**  - - - - - - - -
**
**  Gregorian calendar to year and day in year (in a Julian calendar
**  aligned to the 20th/21st century Gregorian calendar).
**
**  Given:
**     iy,im,id     int    year, month, day in Gregorian calendar
**
**  Returned:
**     ny          int    year (re-aligned Julian calendar)
**     nd          int    day in year (1 = January 1st)
**     jstat       int    status:
**                          0 = OK
**                          1 = bad year (before -4711)
**                          2 = bad month
**                          3 = bad day (but conversion performed)
**
**  Notes:
**
**  1  This function exists to support the low-accuracy functions
**     slaEarth, slaMoon and slaEcor.
**
**  2  Between 1900 March 1 and 2100 February 28 it returns answers
**     which are consistent with the ordinary Gregorian calendar.
**     Outside this range there will be a discrepancy which increases
**     by one day for every non-leap century year.
**
**  3  The essence of the algorithm is first to express the Gregorian
**     date as a Julian Day Number and then to convert this back to
**     a Julian calendar date, with day-in-year instead of month and
**     day.  See 12.92-1 and 12.95-1 in the reference.
**
**  Reference:  Explanatory Supplement to the Astronomical Almanac,
**              ed P.K.Seidelmann, University Science Books (1992),
**              p604-606.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCombn  ( int nsel, int ncand, int list[], int* j )
/*
**  - - - - - - - - -
**   s l a C o m b n
**  - - - - - - - - -
**
**  Generate the next combination, a subset of a specified size chosen
**  from a specified number of items.
**
**  Given:
**     nsel    int        number of items (subset size)
**     ncand   int        number of candidates (set size)
**
**  Given and returned:
**     list    int[nsel]  latest combination, list[0]=0 to initialize
**
**  Returned:
**     *j      int        status: -1 = illegal nsel or ncand
**                                 0 = OK
**                                +1 = no more combinations available
**
**  Notes:
**
**  1) nsel and ncand must both be at least 1, and nsel must be less
**     than or equal to ncand.
**
**  2) This function returns, in the list array, a subset of nsel
**     integers chosen from the range 1 to ncand inclusive, in ascending
**     order.  Before calling the function for the first time, the
**     caller must set the first element of the list array to zero (any
**     value less than 1 will do) to cause initialization.
**
**  2) The first combination to be generated is:
**
**        list[0]=1, list[1]=2, ..., list[nsel-1]=nsel
**
**     This is also the combination returned for the "finished" (j=1)
**     case.
**
**     The final permutation to be generated is:
**
**        list[0]=ncand, list[1]=ncand-1, ..., list[nsel-1]=ncand-nsel+1
**
**  3) If the "finished" (j=1) status is ignored, the function
**     continues to deliver combinations, the pattern repeating
**     every ncand!/(nsel!*(ncand-nsel)!) calls.
**
**  4) The algorithm is by R.F.Warren-Smith (private communication).
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCr2af ( int ndp, float angle, char *sign, int idmsf[4] )
/*
**  - - - - - - - - -
**   s l a C r 2 a f
**  - - - - - - - - -
**
**  Convert an angle in radians into degrees, arcminutes, arcseconds.
**
**  (single precision)
**
**  Given:
**     ndp       int      number of decimal places of arcseconds
**     angle     float    angle in radians
**
**  Returned:
**     sign      *char    '+' or '-'
**     idmsf     int[4]   degrees, arcminutes, arcseconds, fraction
**
**  Called:
**     slaDd2tf
**
** Notes:
**
** 1  ndp less than zero is interpreted as zero.
**
** 2  The largest useful value for ndp is determined by the size of
**    angle, the format of float floating-point numbers on the target
**    machine, and the risk of overflowing idmsf[3].  On some
**    architectures, for angle up to 2pi, the available floating-
**    point precision corresponds roughly to ndp=3.  This is well
**    below the ultimate limit of ndp=9 set by the capacity of a
**    typical 32-bit idmsf[3].
**
** 3  The absolute value of angle may exceed 2pi.  In cases where it
**    does not, it is up to the caller to test for and handle the case
**    where angle is very nearly 2pi and rounds up to 360 deg, by
**    testing for idmsf[0]=360 and setting idmsf[0-3] to zero.
**
**  Defined in slamac.h:  D15B29
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCr2tf ( int ndp, float angle, char *sign, int ihmsf[4] )
/*
**  - - - - - - - - -
**   s l a C r 2 t f
**  - - - - - - - - -
**
**  Convert an angle in radians into hours, minutes, seconds.
**
**  (single precision)
**
**  Given:
**     ndp       int      number of decimal places of seconds
**     angle     float    angle in radians
**
**  Returned:
**     sign      char*    '+' or '-'
**     ihmsf     int(4)   hours, minutes, seconds, fraction
**
** Notes:
**
** 1  ndp less than zero is interpreted as zero.
**
** 2  The largest useful value for ndp is determined by the size of
**    angle, the format of float floating-point numbers on the target
**    machine, and the risk of overflowing ihmsf[3].  On some
**    architectures, for angle up to 2pi, the available floating-point
**    precision corresponds roughly to ndp=3.  This is well below the
**    ultimate limit of ndp=9 set by the capacity of a typical 32-bit
**    ihmsf[3].
**
** 3  The absolute value of angle may exceed 2pi.  In cases where it
**    does not, it is up to the caller to test for and handle the case
**    where angle is very nearly 2pi and rounds up to 24 hours, by
**    testing for ihmsf[0]=24 and setting ihmsf[0-3] to zero.
**
**  Called:
**     slaDd2tf
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCs2c ( float a, float b, float v[3] )
/*
**  - - - - - - - -
**   s l a C s 2 c
**  - - - - - - - -
**
**  Spherical coordinates to direction cosines (single precision)
**
**  Given:
**     a,b      float     spherical coordinates in radians
**                           (RA,Dec), (long,lat) etc.
**
**  Returned:
**     v        float[3]  x,y,z unit vector
**
**  The spherical coordinates are longitude (+ve anticlockwise looking
**  from the +ve latitude pole) and latitude.  The Cartesian coordinates
**  are right handed, with the x axis at zero longitude and latitude,
**  and the z axis at the +ve latitude pole.
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCs2c6 ( float a, float b, float r, float ad,
                float bd, float rd, float v[6] )
/*
**  - - - - - - - - -
**   s l a C s 2 c 6
**  - - - - - - - - -
**
**  Conversion of position & velocity in spherical coordinates
**  to Cartesian coordinates.
**
**  (single precision)
**
**  Given:
**     a     float      longitude (radians)
**     b     float      latitude (radians)
**     r     float      radial coordinate
**     ad    float      longitude derivative (radians per unit time)
**     bd    float      latitude derivative (radians per unit time)
**     rd    float      radial derivative
**
**  Returned:
**     v     float(6)   Cartesian position & velocity vector
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCtf2d ( int ihour, int imin, float sec, float *days, int *j )
/*
**  - - - - - - - - -
**   s l a C t f 2 d
**  - - - - - - - - -
**
**  Convert hours, minutes, seconds to days.
**
**  (single precision)
**
**  Given:
**     ihour       int       hours
**     imin        int       minutes
**     sec         float     seconds
**
**  Returned:
**     *days       float     interval in days
**     *j          int       status:  0 = OK
**                                    1 = ihour outside range 0-23
**                                    2 = imin outside range 0-59
**                                    3 = sec outside range 0-59.999...
**
**  Notes:
**
**     1)  The result is computed even if any of the range checks fail.
**
**     2)  The sign must be dealt with outside this function.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaCtf2r ( int ihour, int imin, float sec, float *rad, int *j )
/*
**  - - - - - - - - -
**   s l a C t f 2 r
**  - - - - - - - - -
**
**  Convert hours, minutes, seconds to radians.
**
**  (single precision)
**
**  Given:
**     ihour       int       hours
**     imin        int       minutes
**     sec         float     seconds
**
**  Returned:
**     *rad        float     angle in radians
**     *j          int       status:  0 = OK
**                                    1 = ihour outside range 0-23
**                                    2 = imin outside range 0-59
**                                    3 = sec outside range 0-59.999...
**
**  Called:
**     slaDtf2d
**
**  Notes:
**
**     1)  The result is computed even if any of the range checks fail.
**
**     2)  The sign must be dealt with outside this function.
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDaf2r ( int ideg, int iamin, double asec, double *rad, int *j )
/*
**  - - - - - - - - -
**   s l a D a f 2 r
**  - - - - - - - - -
**
**  Convert degrees, arcminutes, arcseconds to radians.
**
**  (double precision)
**
**  Given:
**     ideg        int       degrees
**     iamin       int       arcminutes
**     asec        double    arcseconds
**
**  Returned:
**     *rad        double    angle in radians
**     *j          int       status:  0 = OK
**                                    1 = ideg outside range 0-359
**                                    2 = iamin outside range 0-59
**                                    3 = asec outside range 0-59.999...
**
**  Notes:
**     1)  The result is computed even if any of the range checks fail.
**
**     2)  The sign must be dealt with outside this function.
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDafin ( char *string, int *iptr, double *a, int *j )
/*
**  - - - - - - - - -
**   s l a D a f i n
**  - - - - - - - - -
**
**  Sexagesimal character string to angle.
**
**  (double precision)
**
**  Given:
**     string  char*   string containing deg, arcmin, arcsec fields
**     iptr    int     where to start decode at (1st = 1)
**
**  Returned:
**     iptr    int     advanced past the decoded angle
**     a       double  angle in radians
**     j       int     status:  0 = OK
**                             +1 = default, A unchanged
**                             -1 = bad degrees      )
**                             -2 = bad arcminutes   )  (note 3)
**                             -3 = bad arcseconds   )
**
**  Example:
**
**    argument    before                           after
**
**    string      '-57 17 44.806  12 34 56.7'      unchanged
**    iptr        1                                16 (points to 12...)
**
**    a           ?                                -1.00000
**    j           ?                                0
**
**    A further call to slaDafin, without adjustment of iptr, will
**    decode the second angle, 12deg 34min 56.7sec.
**
**  Notes:
**
**     1)  The first three "fields" in string are degrees, arcminutes,
**         arcseconds, separated by spaces or commas.  The degrees field
**         may be signed, but not the others.  The decoding is carried
**         out by the dfltin function and is free-format.
**
**     2)  Successive fields may be absent, defaulting to zero.  For
**         zero status, the only combinations allowed are degrees alone,
**         degrees and arcminutes, and all three fields present.  If all
**         three fields are omitted, a status of +1 is returned and a is
**         unchanged.  In all other cases a is changed.
**
**     3)  Range checking:
**           The degrees field is not range checked.  However, it is
**           expected to be integral unless the other two fields are
**           absent.  The arcminutes field is expected to be 0-59, and
**           integral if the arcseconds field is present.  If the
**           arcseconds field is absent, the arcminutes is expected to
**           be 0-59.9999...  The arcseconds field is expected to be
**           0-59.9999...
**
**     4)  Decoding continues even when a check has failed.  Under these
**         circumstances the field takes the supplied value, defaulting
**         to zero, and the result a is computed and returned.
**
**     5)  Further fields after the three expected ones are not treated
**         as an error.  The pointer iptr is left in the correct state
**         for further decoding with the present function or with
**         slaDfltin etc.  See the example, above.
**
**     6)  If string contains hours, minutes, seconds instead of degrees
**         etc, or if the required units are turns (or days) instead of
**         radians, the result a should be multiplied as follows:
**           for        to obtain    multiply
**           string     a in         a by
**           d ' "      radians      1       =  1.0
**           d ' "      turns        1/2pi   =  0.1591549430918953358
**           h m s      radians      15      =  15.0
**           h m s      days         15/2pi  =  2.3873241463784300365
**
**  Called:  slaDfltin
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDat ( double utc )
/*
**  - - - - - - -
**   s l a D a t
**  - - - - - - -
**
**  Increment to be applied to Coordinated Universal Time UTC to give
**  International Atomic Time TAI.
**
**  (double precision)
**
**  Given:
**     utc      double      UTC date as a modified JD (JD-2400000.5)
**
**  Result:  TAI-UTC in seconds
**
**  Notes:
**
**  1  The UTC is specified to be a date rather than a time to indicate
**     that care needs to be taken not to specify an instant which lies
**     within a leap second.  Though in most cases the utc argument can
**     include the fractional part, correct behaviour on the day of a
**     leap second can only be guaranteed up to the end of the second
**     23:59:59.
**
**  2  For epochs from 1961 January 1 onwards, the expressions from the
**     file ftp://maia.usno.navy.mil/ser7/tai-utc.dat are used.
**
**  3  The 5ms time step at 1961 January 1 is taken from 2.58.1 (p87) of
**     the 1992 Explanatory Supplement.
**
**  4  UTC began at 1960 January 1.0 (JD 2436934.5) and it is improper
**     to call the function with an earlier epoch.  However, if this
**     is attempted, the TAI-UTC expression for the year 1960 is used.
**
**     :-----------------------------------------:
**     :                                         :
**     :                IMPORTANT                :
**     :                                         :
**     :  This function must be updated on each  :
**     :     occasion that a leap second is      :
**     :                announced                :
**     :                                         :
**     :  Latest leap second:  2006 January 1    :
**     :                                         :
**     :-----------------------------------------:
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDav2m ( double axvec[3], double rmat[3][3] )
/*
**  - - - - - - - - -
**   s l a D a v 2 m
**  - - - - - - - - -
**
**  Form the rotation matrix corresponding to a given axial vector.
**
**  (double precision)
**
**  A rotation matrix describes a rotation about some arbitrary axis,
**  called the Euler axis.  The "axial vector" supplied to this function
**  has the same direction as the Euler axis, and its magnitude is the
**  amount of rotation in radians.
**
**  Given:
**    axvec  double[3]     axial vector (radians)
**
**  Returned:
**    rmat   double[3][3]  rotation matrix
**
**  If axvec is null, the unit matrix is returned.
**
**  The reference frame rotates clockwise as seen looking along
**  the axial vector from the origin.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDbear ( double a1, double b1, double a2, double b2 )
/*
**  - - - - - - - - -
**   s l a D b e a r
**  - - - - - - - - -
**
**  Bearing (position angle) of one point on a sphere relative
**  to another.
**
**  (double precision)
**
**  Given:
**     a1,b1    double    spherical coordinates of one point
**     a2,b2    double    spherical coordinates of the other point
**
**  (The spherical coordinates are RA,Dec, Long,Lat etc, in radians.)
**
**  The result is the bearing (position angle), in radians, of point
**  a2,b2 as seen from point a1,b1.  It is in the range +/- pi.  The
**  sense is such that if a2,b2 is a small distance east of a1,b1,
**  the bearing is about +pi/2.  Zero is returned if the two points
**  are coincident.
**
**  If either b-coordinate is outside the range +/- pi/2, the
**  result may correspond to "the long way round".
**
**  The function slaDpav performs an equivalent function except
**  that the points are specified in the form of Cartesian unit
**  vectors.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDbjin ( char *string, int *nstrt,
                double *dreslt, int *jf1, int *jf2 )
/*
**  - - - - - - - - -
**   s l a D b j i n
**  - - - - - - - - -
**
**  Convert free-format input into double precision floating point,
**  using slaDfltin but with special syntax extensions.
**
**  The purpose of the syntax extensions is to help cope with mixed
**  FK4 and FK5 data.  In addition to the syntax accepted by slaDfltin,
**  the following two extensions are recognized by dbjin:
**
**     1)  A valid non-null field preceded by the character 'B'
**         (or 'b') is accepted.
**
**     2)  A valid non-null field preceded by the character 'J'
**         (or 'j') is accepted.
**
**  The calling program is notified of the incidence of either of these
**  extensions through an supplementary status argument.  The rest of
**  the arguments are as for slaDfltin.
**
**  Given:
**     *string    char      string containing field to be decoded
**     *nstrt     int       where to start decode (1st = 1)
**
**
**  Returned:
**     *nstrt     int       incremented
**     *dreslt    double    result
**     *jf1       int       dfltin status: -1 = -OK
**                                          0 = +OK
**                                         +1 = null field
**                                         +2 = error
**     *jf2       int       syntax flag:  0 = normal slaDfltin syntax
**                                       +1 = 'B' or 'b'
**                                       +2 = 'J' or 'j'
**
**  Called:  slaDfltin
**
**  For details of the basic syntax, see slaDfltin.
**
**  Last revision:   2 January 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDc62s ( double v[6], double *a, double *b, double *r,
                double *ad, double *bd, double *rd )
/*
**  - - - - - - - - -
**   s l a D c 6 2 s
**  - - - - - - - - -
**
**  Conversion of position & velocity in Cartesian coordinates
**  to spherical coordinates.
**
**  (double precision)
**
**  Given:
**     v     double[6]  Cartesian position & velocity vector
**
**  Returned:
**     *a    double     longitude (radians)
**     *b    double     latitude (radians)
**     *r    double     radial coordinate
**     *ad   double     longitude derivative (radians per unit time)
**     *bd   double     latitude derivative (radians per unit time)
**     *rd   double     radial derivative
**
**  Last revision:   11 June 1998
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDcc2s ( double v[3], double *a, double *b )
/*
**  - - - - - - - - -
**   s l a D c c 2 s
**  - - - - - - - - -
**
**  Cartesian to spherical coordinates.
**
**  (double precision)
**
**  Given:
**     v       double[3]   x,y,z vector
**
**  Returned:
**     *a,*b   double      spherical coordinates in radians
**
**  The spherical coordinates are longitude (+ve anticlockwise looking
**  from the +ve latitude pole) and latitude.  The Cartesian coordinates
**  are right handed, with the x axis at zero longitude and latitude,
**  and the z axis at the +ve latitude pole.
**
**  If v is null, zero a and b are returned.  At either pole, zero a is
**  returned.
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDcmpf ( double coeffs[6],
                double *xz, double *yz, double *xs,
                double *ys, double *perp, double *orient )
/*
**  - - - - - - - - -
**   s l a D c m p f
**  - - - - - - - - -
**
**  Decompose an [x,y] linear fit into its constituent parameters:
**  zero points, scales, nonperpendicularity and orientation.
**
**  Given:
**     coeffs    double[6]     transformation coefficients (see note)
**
**  Returned:
**     *xz       double        x zero point
**     *yz       double        y zero point
**     *xs       double        x scale
**     *ys       double        y scale
**     *perp     double        nonperpendicularity (radians)
**     *orient   double        orientation (radians)
**
**  Called:  slaDrange
**
**  The model relates two sets of [x,y] coordinates as follows.
**  Naming the elements of coeffs:
**
**     coeffs[0] = a
**     coeffs[1] = b
**     coeffs[2] = c
**     coeffs[3] = d
**     coeffs[4] = e
**     coeffs[5] = f
**
**  The model transforms coordinates [x1,y1] into coordinates
**  [x2,y2] as follows:
**
**     x2 = a + b*x1 + c*y1
**     y2 = d + e*x1 + f*y1
**
**  The transformation can be decomposed into four steps:
**
**     1)  Zero points:
**
**             x' = xz + x1
**             y' = yz + y1
**
**     2)  Scales:
**
**             x'' = xs*x'
**             y'' = ys*y'
**
**     3)  Nonperpendicularity:
**
**             x''' = cos(perp/2)*x'' + sin(perp/2)*y''
**             y''' = sin(perp/2)*x'' + cos(perp/2)*y''
**
**     4)  Orientation:
**
**             x2 = cos(orient)*x''' + sin(orient)*y'''
**             y2 =-sin(orient)*y''' + cos(orient)*y'''
**
**  See also slaFitxy, slaPxy, slaInvf, slaXy2xy
**
**  Last revision:   19 December 2001
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDcs2c ( double a, double b, double v[3] )
/*
**  - - - - - - - - -
**   s l a D c s 2 c
**  - - - - - - - - -
**
**  Spherical coordinates to direction cosines (double precision)
**
**  Given:
**     a,b       double      spherical coordinates in radians
**                           (RA,Dec), (long,lat) etc
**
**  Returned:
**     v         double[3]   x,y,z unit vector
**
**  The spherical coordinates are longitude (+ve anticlockwise looking
**  from the +ve latitude pole) and latitude.  The Cartesian coordinates
**  are right handed, with the x axis at zero longitude and latitude,
**  and the z axis at the +ve latitude pole.
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDd2tf ( int ndp, double days, char *sign, int ihmsf[4] )
/*
**  - - - - - - - - -
**   s l a D d 2 t f
**  - - - - - - - - -
**
**  Convert an interval in days into hours, minutes, seconds.
**
**  (double precision)
**
**  Given:
**     ndp       int      number of decimal places of seconds
**     days      double   interval in days
**
**  Returned:
**     *sign     char     '+' or '-'
**     ihmsf     int[4]   hours, minutes, seconds, fraction
**
**  Notes:
**
**  1  ndp less than zero is interpreted as zero.
**
**  2  The largest useful value for ndp is determined by the size of
**     days, the format of double floating-point numbers on the target
**     machine, and the risk of overflowing ihmsf[3].  On some
**     architectures, for days up to 1.0, the available floating-point
**     precision corresponds roughly to ndp=12.  However, the practical
**     limit is ndp=9, set by the capacity of a typical 32-bit ihmsf[3].
**
**  3  The absolute value of days may exceed 1.0.  In cases where it
**     does not, it is up to the caller to test for and handle the case
**     where days is very nearly 1.0 and rounds up to 24 hours, by
**     testing for ihmsf[0]=24 and setting ihmsf[0-3] to zero.
**
**  Last revision:   26 December 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDe2h ( double ha, double dec, double phi, double *az, double *el )
/*
**  - - - - - - - -
**   s l a D e 2 h
**  - - - - - - - -
**
**  Equatorial to horizon coordinates:  HA,Dec to Az,El
**
**  (double precision)
**
**  Given:
**     ha          double       hour angle
**     dec         double       declination
**     phi         double       observatory latitude
**
**  Returned:
**     *az         double       azimuth
**     *el         double       elevation
**
**  Notes:
**
**  1)  All the arguments are angles in radians.
**
**  2)  Azimuth is returned in the range 0-2pi;  north is zero,
**      and east is +pi/2.  Elevation is returned in the range
**      +/-pi/2.
**
**  3)  The latitude must be geodetic.  In critical applications,
**      corrections for polar motion should be applied.
**
**  4)  In some applications it will be important to specify the
**      correct type of hour angle and declination in order to
**      produce the required type of azimuth and elevation.  In
**      particular, it may be important to distinguish between
**      elevation as affected by refraction, which would
**      require the "observed" HA,Dec, and the elevation
**      in vacuo, which would require the "topocentric" HA,Dec.
**      If the effects of diurnal aberration can be neglected, the
**      "apparent" HA,Dec may be used instead of the topocentric
**      HA,Dec.
**
**  5)  No range checking of arguments is carried out.
**
**  6)  In applications which involve many such calculations, rather
**      than calling the present function it will be more efficient to
**      use inline code, having previously computed fixed terms such
**      as sine and cosine of latitude, and (for tracking a star)
**      sine and cosine of declination.
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDeuler ( char *order, double phi, double theta,
                 double psi, double rmat[3][3] )
/*
**  - - - - - - - - - -
**   s l a D e u l e r
**  - - - - - - - - - -
**
**  Form a rotation matrix from the Euler angles - three successive
**  rotations about specified Cartesian axes.
**
**  (double precision)
**
**  Given:
**    *order char     specifies about which axes the rotations occur
**    phi    double   1st rotation (radians)
**    theta  double   2nd rotation (   "   )
**    psi    double   3rd rotation (   "   )
**
**  Returned:
**    rmat   double[3][3]  rotation matrix
**
**  A rotation is positive when the reference frame rotates
**  anticlockwise as seen looking towards the origin from the
**  positive region of the specified axis.
**
**  The characters of order define which axes the three successive
**  rotations are about.  A typical value is 'zxz', indicating that
**  rmat is to become the direction cosine matrix corresponding to
**  rotations of the reference frame through phi radians about the
**  old z-axis, followed by theta radians about the resulting x-axis,
**  then psi radians about the resulting z-axis.
**
**  The axis names can be any of the following, in any order or
**  combination:  x, y, z, uppercase or lowercase, 1, 2, 3.  Normal
**  axis labelling/numbering conventions apply;  the xyz (=123)
**  triad is right-handed.  Thus, the 'zxz' example given above
**  could be written 'zxz' or '313' (or even 'zxz' or '3xz').  Order
**  is terminated by length or by the first unrecognized character.
**
**  Fewer than three rotations are acceptable, in which case the later
**  angle arguments are ignored.  Zero rotations leaves rmat set to the
**  identity matrix.
**
**  Last revision:   2 January 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDfltin ( char *string, int *nstrt, double *dreslt, int *jflag )
/*
**  - - - - - - - - - -
**   s l a D f l t i n
**  - - - - - - - - - -
**
**  Convert free-format input into double precision floating point.
**
**  Given:
**     *string     char       string containing field to be decoded
**     *nstrt      int        where to start decode (1st = 1)
**
**  Returned:
**     *nstrt      int        advanced to next field
**     *dreslt     double     result
**     *jflag      int        -1 = -OK, 0 = +OK, 1 = null field, 2 = error
**
**  Called:  idchf
**
**  Notes:
**
**     1     A tab character is interpreted as a space, and lower
**           case d,e are interpreted as upper case.
**
**     2     The basic format is #^.^@#^ where # means + or -,
**           ^ means a decimal subfield and @ means D or E.
**
**     3     Spaces:
**             Leading spaces are ignored.
**             Embedded spaces are allowed only after # and D or E,
**             and after . where the first ^ is absent.
**             Trailing spaces are ignored;  the first signifies
**             end of decoding and subsequent ones are skipped.
**
**     4     Field separators:
**             Any character other than +,-,0-9,.,D,E or space may be
**             used to end a field.  Comma is recognized by slaDfltin
**             as a special case; it is skipped, leaving the
**             pointer on the next character.  See 12, below.
**
**     5     Both signs are optional.  The default is +.
**
**     6     The mantissa defaults to 1.
**
**     7     The exponent defaults to e0.
**
**     8     The decimal subfields may be of any length.
**
**     9     The decimal point is optional for whole numbers.
**
**     10    A null field is one that does not begin with
**           +,-,0-9,.,D or E, or consists entirely of spaces.
**           If the field is null, jflag is set to 1 and dreslt
**           is left untouched.
**
**     11    nstrt = 1 for the first character in the string.
**
**     12    On return from slaDfltin, nstrt is set ready for the next
**           decode - following trailing blanks and (if used) the
**           comma separator.  If a separator other than comma is
**           being used, nstrt must be incremented before the next
**           call to slaDfltin.
**
**     13    Errors (jflag=2) occur when:
**             a)  A +, -, D or E is left unsatisfied.
**             b)  The decimal point is present without at least
**                 one decimal subfield.
**             c)  An exponent more than 100 has been presented.
**
**     14    When an error has been detected, nstrt is left
**           pointing to the character following the last
**           one used before the error came to light.  This
**           may be after the point at which a more sophisticated
**           program could have detected the error.  For example,
**           slaDfltin does not detect that '1e999' is unacceptable
**           until the whole field has been read.
**
**     15    Certain highly unlikely combinations of mantissa &
**           exponent can cause arithmetic faults during the
**           decode, in some cases despite the fact that they
**           together could be construed as a valid number.
**
**     16    Decoding is left to right, one pass.
**
**     17    End of field may occur in either of two ways:
**             a)  As dictated by the string length.
**             b)  Detected during the decode.
**                 (b overrides a.)
**
**     18    See also slaFlotin, slaIntin and slaInt2in.
**
**  Last revision:   12 April 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDh2e ( double az, double el, double phi, double *ha, double *dec )
/*
**  - - - - - - - -
**   s l a D h 2 e
**  - - - - - - - -
**
**  Horizon to equatorial coordinates:  Az,El to HA,Dec
**
**  (double precision)
**
**  Given:
**     az          double       azimuth
**     el          double       elevation
**     phi         double       observatory latitude
**
**  Returned:
**     *ha         double       hour angle
**     *dec        double       declination
**
**  Notes:
**
**  1)  All the arguments are angles in radians.
**
**  2)  The sign convention for azimuth is north zero, east +pi/2.
**
**  3)  HA is returned in the range +/-pi.  Declination is returned
**      in the range +/-pi/2.
**
**  4)  The is latitude is (in principle) geodetic.  In critical
**      applications, corrections for polar motion should be applied.
**
**  5)  In some applications it will be important to specify the
**      correct type of elevation in order to produce the required
**      type of HA,Dec.  In particular, it may be important to
**      distinguish between the elevation as affected by refraction,
**      which will yield the "observed" HA,Dec, and the elevation
**      in vacuo, which will yield the "topocentric" HA,Dec.  If the
**      effects of diurnal aberration can be neglected, the
**      topocentric HA,Dec may be used as an approximation to the
**      "apparent" HA,Dec.
**
**  6)  No range checking of arguments is done.
**
**  7)  In applications which involve many such calculations, rather
**      than calling the present function it will be more efficient to
**      use inline code, having previously computed fixed terms such
**      as sine and cosine of latitude.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDimxv ( double dm[3][3], double va[3], double vb[3] )
/*
**  - - - - - - - - -
**   s l a D i m x v
**  - - - - - - - - -
**
**  Performs the 3-d backward unitary transformation:
**
**     vector vb = (inverse of matrix dm) * vector va
**
**  (double precision)
**
**  (n.b.  The matrix must be unitary, as this function assumes that
**   the inverse and transpose are identical)
**
**
**  Given:
**     dm       double[3][3]   matrix
**     va       double[3]      vector
**
**  Returned:
**     vb       double[3]      result vector
**
**  Note:  va and vb may be the same array.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDjcal ( int ndp, double djm, int iymdf[4], int *j )
/*
**  - - - - - - - - -
**   s l a D j c a l
**  - - - - - - - - -
**
**  Modified Julian Date to Gregorian calendar, expressed
**  in a form convenient for formatting messages (namely
**  rounded to a specified precision, and with the fields
**  stored in a single array).
**
**  Given:
**     ndp      int       number of decimal places of days in fraction
**     djm      double    Modified Julian Date (JD-2400000.5)
**
**  Returned:
**     iymdf    int[4]    year, month, day, fraction in Gregorian calendar
**     *j       int       status:  nonzero = out of range
**
**  Any date after 4701BC March 1 is accepted.
**
**  Large ndp values risk internal overflows.  It is typically safe
**  to use up to ndp=4.
**
**  The algorithm is adapted from Hatcher 1984 (QJRAS 25, 53-55).
**
**  Defined in slamac.h:  dmod
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDjcl ( double djm, int *iy, int *im, int *id, double *fd, int *j)
/*
**  - - - - - - - -
**   s l a D j c l
**  - - - - - - - -
**
**  Modified Julian Date to Gregorian year, month, day,
**  and fraction of a day.
**
**  Given:
**     djm      double     Modified Julian Date (JD-2400000.5)
**
**  Returned:
**     *iy      int        year
**     *im      int        month
**     *id      int        day
**     *fd      double     fraction of day
**     *j       int        status:
**                      -1 = unacceptable date (before 4701BC March 1)
**
**  The algorithm is adapted from Hatcher 1984 (QJRAS 25, 53-55).
**
**  Defined in slamac.h:  dmod
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDm2av ( double rmat[3][3], double axvec[3] )
/*
**  - - - - - - - - -
**   s l a D m 2 a v
**  - - - - - - - - -
**
**  From a rotation matrix, determine the corresponding axial vector.
**
**  (double precision)
**
**  A rotation matrix describes a rotation about some arbitrary axis,
**  called the Euler axis.  The "axial vector" returned by this function
**  has the same direction as the Euler axis, and its magnitude is the
**  amount of rotation in radians.  (The magnitude and direction can be
**  separated by means of the function slaDvn.)
**
**  Given:
**    rmat   double[3][3]   rotation matrix
**
**  Returned:
**    axvec  double[3]      axial vector (radians)
**
**  The reference frame rotates clockwise as seen looking along
**  the axial vector from the origin.
**
**  If rmat is null, so is the result.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDmat ( int n, double *a, double *y, double *d, int *jf, int *iw)
/*
**  - - - - - - - -
**   s l a D m a t
**  - - - - - - - -
**
**  Matrix inversion & solution of simultaneous equations.
**
**  (double precision)
**
**  For the set of n simultaneous equations in n unknowns:
**     a.y = x
**
**  where:
**     a is a non-singular n x n matrix
**     y is the vector of n unknowns
**     x is the known vector
**
**  slaDmat computes:
**     the inverse of matrix a
**     the determinant of matrix a
**     the vector of n unknowns
**
**  Arguments:
**
**     symbol  type dimension           before              after
**
**       n      int                  no. of unknowns       unchanged
**       *a     double  [n][n]           matrix             inverse
**       *y     double   [n]              vector            solution
**       *d     double                      -             determinant
**    >  *jf    int                         -           singularity flag
**       *iw    int      [n]                -              workspace
**
**
**    >  jf is the singularity flag.  If the matrix is non-singular,
**       jf=0 is returned.  If the matrix is singular, jf=-1 & d=0.0 are
**       returned.  In the latter case, the contents of array a on return
**       are undefined.
**
**  Algorithm:
**     Gaussian elimination with partial pivoting.
**
**  Speed:
**     Very fast.
**
**  Accuracy:
**     Fairly accurate - errors 1 to 4 times those of functions
**     optimized for accuracy.
**
**  Example call (note handling of "adjustable dimension" 2D array):
**
**     double a[MP][MP], v[MP], d;
**     int j, iw[MP];
**      :
**     slaDmat ( n, (double *) a, v, &d, &j, iw );
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDmoon ( double date, double pv[6] )
/*
**  - - - - - - - - -
**   s l a D m o o n
**  - - - - - - - - -
**
**  Approximate geocentric position and velocity of the Moon
**  (double precision).
**
**  Given:
**     date     double      TDB (loosely ET) as a Modified Julian Date
**                                                  (JD-2400000.5)
**
**  Returned:
**     pv       double[6]   Moon x,y,z,xdot,ydot,zdot, mean equator
**                                   and equinox of date (AU, AU/s)
**
**  Notes:
**
**  1  This function is a full implementation of the algorithm
**     published by Meeus (see reference).
**
**  2  Meeus quotes accuracies of 10 arcsec in longitude, 3 arcsec in
**     latitude and 0.2 arcsec in HP (equivalent to about 20 km in
**     distance).  Comparison with JPL DE200 over the interval
**     1960-2025 gives RMS errors of 3.7 arcsec and 83 mas/hour in
**     longitude, 2.3 arcsec and 48 mas/hour in latitude, 11 km
**     and 81 mm/s in distance.  The maximum errors over the same
**     interval are 18 arcsec and 0.50 arcsec/hour in longitude,
**     11 arcsec and 0.24 arcsec/hour in latitude, 40 km and 0.29 m/s
**     in distance. 
**
**  3  The original algorithm is expressed in terms of the obsolete
**     timescale Ephemeris Time.  Either TDB or TT can be used, but
**     not UT without incurring significant errors (30 arcsec at
**     the present time) due to the Moon's 0.5 arcsec/sec movement.
**
**  4  The algorithm is based on pre IAU 1976 standards.  However,
**     the result has been moved onto the new (FK5) equinox, an
**     adjustment which is in any case much smaller than the
**     intrinsic accuracy of the procedure.
**
**  5  Velocity is obtained by a complete analytical differentiation
**     of the Meeus model.
**
**  Reference:
**     Meeus, l'Astronomie, June 1984, p348.
**
**  Defined in slamac.h:  DD2R, DAS2R, DS2R, dmod
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDmxm ( double a[3][3], double b[3][3], double c[3][3] )
/*
**  - - - - - - - -
**   s l a D m x m
**  - - - - - - - -
**
**  Product of two 3x3 matrices:
**    matrix c  =  matrix a  x  matrix b
**
**  (double precision)
**
**  Given:
**     a      double[3][3]        matrix
**     b      double[3][3]        matrix
**
**  Returned:
**     c      double[3][3]        matrix result
**
**  Note:  the same array may be nominated more than once.
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDmxv ( double dm[3][3], double va[3], double vb[3] )
/*
**  - - - - - - - -
**   s l a D m x v
**  - - - - - - - -
**
**  Performs the 3-d forward unitary transformation:
**     vector vb = matrix dm * vector va
**
**  (double precision)
**
**  Given:
**     dm       double[3][3]    matrix
**     va       double[3]       vector
**
**  Returned:
**     vb       double[3]       result vector
**
**  Note:  va and vb may be the same array.
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDpav ( double v1 [ 3 ], double v2 [ 3 ] )
/*
**  - - - - - - - -
**   s l a D p a v
**  - - - - - - - -
**
**  Position angle of one celestial direction with respect to another.
**
**  (double precision)
**
**  Given:
**     v1    double[3]    direction cosines of one point
**     v2    double[3]    direction cosines of the other point
**
**  (The coordinate frames correspond to RA,Dec, Long,Lat etc.)
**
**  The result is the bearing (position angle), in radians, of point
**  v2 with respect to point v1.  It is in the range +/- pi.  The
**  sense is such that if v2 is a small distance east of v1, the
**  bearing is about +pi/2.  Zero is returned if the two points
**  are coincident.
**
**  The vectors v1 and v2 need not be unit vectors.
**
**  The function slaDbear performs an equivalent function except
**  that the points are specified in the form of spherical
**  coordinates.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDr2af ( int ndp, double angle, char *sign, int idmsf[4] )
/*
**  - - - - - - - - -
**   s l a D r 2 a f
**  - - - - - - - - -
**
**  Convert an angle in radians to degrees, arcminutes, arcseconds.
**
**  (double precision)
**
**  Given:
**     ndp       int          number of decimal places of arcseconds
**     angle     double       angle in radians
**
**  Returned:
**     sign      char*        '+' or '-'
**     idmsf     int[4]       degrees, arcminutes, arcseconds, fraction
**
**  Notes:
**
**  1  ndp less than zero is interpreted as zero.
**
**  2  The largest useful value for ndp is determined by the size of
**     angle, the format of double floating-point numbers on the target
**     machine, and the risk of overflowing idmsf[3].  On some
**     architectures, for angle up to 2pi, the available floating-point
**     precision corresponds roughly to ndp=12.  However, the practical
**     limit is ndp=9, set by the capacity of a typical 32-bit idmsf[3].
**
**  3  The absolute value of angle may exceed 2pi.  In cases where it
**     does not, it is up to the caller to test for and handle the case
**     where angle is very nearly 2pi and rounds up to 360 deg, by
**     testing for idmsf[0]=360 and setting idmsf[0-3] to zero.
**
**  Called:
**     slaDd2tf
**
**  Defined in slamac.h:  D15B2P
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDr2tf ( int ndp, double angle, char *sign, int ihmsf[4] )
/*
**  - - - - - - - - -
**   s l a D r 2 t f
**  - - - - - - - - -
**
**  Convert an angle in radians to hours, minutes, seconds.
**
**  (double precision)
**
**  Given:
**     ndp       int          number of decimal places of seconds
**     angle     double       angle in radians
**
**  Returned:
**     sign      char*        '+' or '-'
**     ihmsf     int[4]       hours, minutes, seconds, fraction
**
**  Notes:
**
**  1  ndp less than zero is interpreted as zero.
**
**  2  The largest useful value for ndp is determined by the size of
**     angle, the format of double floating-point numbers on the target
**     machine, and the risk of overflowing ihmsf[3].  On some
**     architectures, for angle up to 2pi, the available floating-
**     point precision corresponds roughly to ndp=12.  However, the
**     practical limit is ndp=9, set by the capacity of a typical 32-bit
**     ihmsf[3].
**
**  3  The absolute value of angle may exceed 2pi.  In cases where it
**     does not, it is up to the caller to test for and handle the case
**     where angle is very nearly 2pi and rounds up to 24 hours, by
**     testing for ihmsf[0]=24 and setting ihmsf[0-3] to zero.
**
**  Called:
**     slaDd2tf
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDrange ( double angle )
/*
**  - - - - - - - - - -
**   s l a D r a n g e
**  - - - - - - - - - -
**
**  Normalize angle into range +/- pi.
**
**  (double precision)
**
**  Given:
**     angle     double      the angle in radians
**
**  The result is angle expressed in the range +/- pi.
**
**  Defined in slamac.h:  DPI, D2PI, dmod
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDranrm ( double angle )
/*
**  - - - - - - - - - -
**   s l a D r a n r m
**  - - - - - - - - - -
**
**  Normalize angle into range 0-2 pi.
**
**  (double precision)
**
**  Given:
**     angle     double      the angle in radians
**
**  The result is angle expressed in the range 0-2 pi (double).
**
**  Defined in slamac.h:  D2PI, dmod
**
**  Last revision:   19 March 1996
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDs2c6 ( double a, double b, double r, double ad,
                double bd, double rd, double v[6] )
/*
**  - - - - - - - - -
**   s l a D s 2 c 6
**  - - - - - - - - -
**
**  Conversion of position & velocity in spherical coordinates
**  to Cartesian coordinates.
**
**  (double precision)
**
**  Given:
**     a     double      longitude (radians)
**     b     double      latitude (radians)
**     r     double      radial coordinate
**     ad    double      longitude derivative (radians per unit time)
**     bd    double      latitude derivative (radians per unit time)
**     rd    double      radial derivative
**
**  Returned:
**     v     double[6]   Cartesian position & velocity vector
**
**  Last revision:   16 November 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDs2tp ( double ra, double dec, double raz, double decz,
                double *xi, double *eta, int *j )
/*
**  - - - - - - - - -
**   s l a D s 2 t p
**  - - - - - - - - -
**
**  Projection of spherical coordinates onto tangent plane
**  ('gnomonic' projection - 'standard coordinates').
**
**  (double precision)
**
**  Given:
**     ra,dec      double   spherical coordinates of point to be projected
**     raz,decz    double   spherical coordinates of tangent point
**
**  Returned:
**     *xi,*eta    double   rectangular coordinates on tangent plane
**     *j          int      status:   0 = OK, star on tangent plane
**                                    1 = error, star too far from axis
**                                    2 = error, antistar on tangent plane
**                                    3 = error, antistar too far from axis
**
**  Last revision:   18 July 1996
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDsep ( double a1, double b1, double a2, double b2 )
/*
**  - - - - - - - -
**   s l a D s e p
**  - - - - - - - -
**
**  Angle between two points on a sphere.
**
**  (double precision)
**
**  Given:
**     a1,b1    double    spherical coordinates of one point
**     a2,b2    double    spherical coordinates of the other point
**
**  (The spherical coordinates are [RA,Dec], [Long,Lat] etc, in radians.)
**
**  The result is the angle, in radians, between the two points.  It
**  is always positive.
**
**  Called:  slaDcs2c, slaDsepv
**
**  Last revision:   7 May 2000
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDsepv ( double v1[3], double v2[3] )
/*
**  - - - - - - - - -
**   s l a D s e p v
**  - - - - - - - - -
**
**  Angle between two vectors.
**
**  (double precision)
**
**  Given:
**     v1      double[3]    first vector
**     v2      double[3]    second vector
**
**  The result is the angle, in radians, between the two vectors.  It
**  is always positive.
**
**  Notes:
**
**  1  There is no requirement for the vectors to be unit length.
**
**  2  If either vector is null, zero is returned.
**
**  3  The simplest formulation would use dot product alone.  However,
**     this would reduce the accuracy for angles near zero and pi.  The
**     algorithm uses both cross product and dot product, which maintains
**     accuracy for all sizes of angle.
**
**  Called:  slaDvxv, slaDvn, slaDvdv
**
**  Last revision:   14 June 2005
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDt ( double epoch )
/*
**  - - - - - -
**   s l a D t
**  - - - - - -
**
**  Estimate the offset between dynamical time and Universal Time
**  for a given historical epoch.
**
**  (double precision)
**
**  Given:
**     epoch    double    (Julian) epoch (e.g. 1850.0)
**
**  The result is a rough estimate of ET-UT (after 1984, TT-UT1) at
**  the given epoch, in seconds.
**
**  Notes:
**
**  1  Depending on the epoch, one of three parabolic approximations
**     is used:
**
**      before 979    Stephenson & Morrison's 390 BC to AD 948 model
**      979 to 1708   Stephenson & Morrison's 948 to 1600 model
**      after 1708    McCarthy & Babcock's post-1650 model
**
**     The breakpoints are chosen to ensure continuity:  they occur
**     at places where the adjacent models give the same answer as
**     each other.
**
**  2  The accuracy is modest, with errors of up to 20 sec during
**     the interval since 1650, rising to perhaps 30 min by 1000 BC.
**     Comparatively accurate values from AD 1600 are tabulated in
**     the Astronomical Almanac (see section K8 of the 1995 AA).
**
**  3  The use of double-precision for both argument and result is
**     purely for compatibility with other SLALIB time functions.
**
**  4  The models used are based on a lunar tidal acceleration value
**     of -26.00 arcsec per century.
**
**  Reference:  Explanatory Supplement to the Astronomical Almanac,
**              ed P.K.Seidelmann, University Science Books (1992),
**              section 2.553, p83.  This contains references to
**              the Stephenson & Morrison and McCarthy & Babcock
**              papers.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDtf2d ( int ihour, int imin, double sec, double *days, int *j )
/*
**  - - - - - - - - -
**   s l a D t f 2 d
**  - - - - - - - - -
**
**  Convert hours, minutes, seconds to days.
**
**  (double precision)
**
**  Given:
**     ihour       int           hours
**     imin        int           minutes
**     sec         double        seconds
**
**  Returned:
**     *days       double        interval in days
**     *j          int           status:  0 = OK
**                                        1 = ihour outside range 0-23
**                                        2 = imin outside range 0-59
**                                        3 = sec outside range 0-59.999...
**
**  Notes:
**
**     1)  The result is computed even if any of the range checks fail.
**
**     2)  The sign must be dealt with outside this function.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDtf2r ( int ihour, int imin, double sec, double *rad, int *j )
/*
**  - - - - - - - - -
**   s l a D t f 2 r
**  - - - - - - - - -
**
**  Convert hours, minutes, seconds to radians.
**
**  (double precision)
**
**  Given:
**     ihour       int           hours
**     imin        int           minutes
**     sec         double        seconds
**
**  Returned:
**     *rad        double        angle in radians
**     *j          int           status:  0 = OK
**                                        1 = ihour outside range 0-23
**                                        2 = imin outside range 0-59
**                                        3 = sec outside range 0-59.999...
**
**  Called:
**     slaDtf2d
**
**  Notes:
**
**     1)  The result is computed even if any of the range checks fail.
**
**     2)  The sign must be dealt with outside this function.
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDtp2s ( double xi, double eta, double raz, double decz,
                double *ra, double *dec )
/*
**  - - - - - - - - -
**   s l a D t p 2 s
**  - - - - - - - - -
**
**  Transform tangent plane coordinates into spherical.
**
**  (double precision)
**
**  Given:
**     xi,eta      double   tangent plane rectangular coordinates
**     raz,decz    double   spherical coordinates of tangent point
**
**  Returned:
**     *ra,*dec    double   spherical coordinates (0-2pi,+/-pi/2)
**
**  Called:  slaDranrm
**
**  Last revision:   3 June 1995
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDtp2v ( double xi, double eta, double v0[3], double v[3] )
/*
**  - - - - - - - - -
**   s l a D t p 2 v
**  - - - - - - - - -
**
**  Given the tangent-plane coordinates of a star and the direction
**  cosines of the tangent point, determine the direction cosines
**  of the star.
**
**  (double precision)
**
**  Given:
**     xi,eta    double      tangent plane coordinates of star
**     v0        double[3]   direction cosines of tangent point
**
**  Returned:
**     v         double[3]   direction cosines of star
**
**  Notes:
**
**  1  If vector v0 is not of unit length, the returned vector v will
**     be wrong.
**
**  2  If vector v0 points at a pole, the returned vector v will be
**     based on the arbitrary assumption that the RA of the tangent
**     point is zero.
**
**  3  This function is the Cartesian equivalent of the function
**     slaDtp2s.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDtps2c ( double xi, double eta, double ra, double dec,
                 double *raz1, double *decz1,
                 double *raz2, double *decz2, int *n )
/*
**  - - - - - - - - - -
**   s l a D t p s 2 c
**  - - - - - - - - - -
**
**  From the tangent plane coordinates of a star of known RA,Dec,
**  determine the RA,Dec of the tangent point.
**
**  (double precision)
**
**  Given:
**     xi,eta        double  tangent plane rectangular coordinates
**     ra,dec        double  spherical coordinates
**
**  Returned:
**     *raz1,*decz1  double  spherical coordinates of TP, solution 1
**     *raz2,*decz2  double  spherical coordinates of TP, solution 2
**     *n            int     number of solutions:
**                            0 = no solutions returned (note 2)
**                            1 = only the first solution is useful (note 3)
**                            2 = both solutions are useful (note 3)
**
**
**  Notes:
**
**  1  The raz1 and raz2 values are returned in the range 0-2pi.
**
**  2  Cases where there is no solution can only arise near the poles.
**     For example, it is clearly impossible for a star at the pole
**     itself to have a non-zero xi value, and hence it is
**     meaningless to ask where the tangent point would have to be
**     to bring about this combination of xi and dec.
**
**  3  Also near the poles, cases can arise where there are two useful
**     solutions.  The argument n indicates whether the second of the
**     two solutions returned is useful;  n=1 indicates only one useful
**     solution, the usual case;  under these circumstances, the second
**     solution corresponds to the "beyond the pole" case, and this is
**     reflected in the values of raz2 and decz2 which are returned.
**
**  4  The decz1 and decz2 values are returned in the range +/-pi, but
**     in the usual, non-pole-crossing, case, the range is +/-pi/2.
**
**  5  This function is the spherical equivalent of the function
**     slaDtpv2c.
**
**  Called:  slaDranrm
**
**  Last revision:   6 December 2005
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDtpv2c ( double xi, double eta, double v[3], double v01[3],
                                                     double v02[3], int *n )
/*
**  - - - - - - - - - -
**   s l a D t p v 2 c
**  - - - - - - - - - -
**
**  Given the tangent-plane coordinates of a star and its direction
**  cosines, determine the direction cosines of the tangent-point.
**
**  (double precision)
**
**  Given:
**     xi,eta    double       tangent plane coordinates of star
**     v         double[3]    direction cosines of star
**
**  Returned:
**     v01       double[3]    direction cosines of TP, solution 1
**     v02       double[3]    direction cosines of TP, solution 2
**     *n        int          number of solutions:
**                             0 = no solutions returned (note 2)
**                             1 = only the first solution is useful (note 3)
**                             2 = both solutions are useful (note 3)
**
**  Notes:
**
**  1  The vector v must be of unit length or the result will be wrong.
**
**  2  Cases where there is no solution can only arise near the poles.
**     For example, it is clearly impossible for a star at the pole
**     itself to have a non-zero xi value, and hence it is meaningless
**     to ask where the tangent point would have to be.
**
**  3  Also near the poles, cases can arise where there are two useful
**     solutions.  The argument n indicates whether the second of the
**     two solutions returned is useful;  n=1 indicates only one useful
**     solution, the usual case.  Under these circumstances, the second
**     solution can be regarded as valid if the vector v02 is
**     interpreted as the "beyond the pole" case.
**
**  4  This function is the Cartesian equivalent of the function
**     slaDtps2c.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDtt ( double utc )
/*
**  - - - - - - -
**   s l a D t t
**  - - - - - - -
**
**  Increment to be applied to Coordinated Universal Time UTC to give
**  Terrestrial Time TT (formerly Ephemeris Time ET).
**
**  (double precision)
**
**  Given:
**     utc    double    UTC date as a modified JD (JD-2400000.5)
**
**  Result:  TT-UTC in seconds
**
**  Notes:
**
**  1  The UTC is specified to be a date rather than a time to indicate
**     that care needs to be taken not to specify an instant which lies
**     within a leap second.  Though in most cases UTC can include the
**     fractional part, correct behaviour on the day of a leap second
**     can only be guaranteed up to the end of the second 23:59:59.
**
**  2  Pre 1972 January 1 a fixed value of 10 + ET-TAI is returned.
**
**  3  See also the function slaDt, which roughly estimates ET-UT for
**     historical epochs.
**
**  Called:  slaDat
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDv2tp ( double v[3], double v0[3], double *xi, double *eta, int *j )
/*
**  - - - - - - - - -
**   s l a D v 2 t p
**  - - - - - - - - -
**
**  Given the direction cosines of a star and of the tangent point,
**  determine the star's tangent-plane coordinates.
**
**  (double precision)
**
**  Given:
**     v         double[3]  direction cosines of star
**     v0        double[3]  direction cosines of tangent point
**
**  Returned:
**     *xi,*eta  double     tangent plane coordinates of star
**     j         int        status:   0  =  OK
**                                    1  =  error, star too far from axis
**                                    2  =  error, antistar on tangent plane
**                                    3  =  error, antistar too far from axis
**
**  Notes:
**
**  1  If vector v0 is not of unit length, or if vector v is of zero
**     length, the results will be wrong.
**
**  2  If v0 points at a pole, the returned xi,eta will be based on the
**     arbitrary assumption that the RA of the tangent point is zero.
**
**  3  This function is the Cartesian equivalent of the function
**     slaDs2tp.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaDvdv ( double va[3], double vb[3] )
/*
**  - - - - - - - -
**   s l a D v d v
**  - - - - - - - -
**
**  Scalar product of two 3-vectors.
**
**  (double precision)
**
**
**  Given:
**      va      double(3)     first vector
**      vb      double(3)     second vector
**
**  The result is the scalar product va.vb (double precision)
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDvn ( double v[3], double uv[3], double *vm )
/*
**  - - - - - - -
**   s l a D v n
**  - - - - - - -
**
**  Normalizes a 3-vector also giving the modulus.
**
**  (double precision)
**
**  Given:
**     v       double[3]      vector
**
**  Returned:
**     uv      double[3]      unit vector in direction of v
**     *vm     double         modulus of v
**
**  Note:  v and uv may be the same array.
**
**  If the modulus of v is zero, uv is set to zero as well.
**
**  Last revision:   6 December 2001
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaDvxv ( double va[3], double vb[3], double vc[3] )
/*
**  - - - - - - - -
**   s l a D v x v
**  - - - - - - - -
**
**  Vector product of two 3-vectors.
**
**  (double precision)
**
**  Given:
**     va      double[3]     first vector
**     vb      double[3]     second vector
**
**  Returned:
**     vc      double[3]     vector result
**
**  Note:  the same vector may be specified more than once.
**
**  Last revision:   6 November 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaE2h ( float ha, float dec, float phi, float *az, float *el )
/*
**  - - - - - - -
**   s l a E 2 h
**  - - - - - - -
**
**  Equatorial to horizon coordinates:  HA,Dec to Az,El
**
**  (single precision)
**
**  Given:
**     ha          float       hour angle
**     dec         float       declination
**     phi         float       observatory latitude
**
**  Returned:
**     *az         float       azimuth
**     *el         float       elevation
**
**  Notes:
**
**  1)  All the arguments are angles in radians.
**
**  2)  Azimuth is returned in the range 0-2pi;  north is zero,
**      and east is +pi/2.  Elevation is returned in the range
**      +/-pi/2.
**
**  3)  The latitude must be geodetic.  In critical applications,
**      corrections for polar motion should be applied.
**
**  4)  In some applications it will be important to specify the
**      correct type of hour angle and declination in order to
**      produce the required type of azimuth and elevation.  In
**      particular, it may be important to distinguish between
**      elevation as affected by refraction, which would
**      require the "observed" HA,Dec, and the elevation
**      in vacuo, which would require the "topocentric" HA,Dec.
**      If the effects of diurnal aberration can be neglected, the
**      "apparent" HA,Dec may be used instead of the topocentric
**      HA,Dec.
**
**  5)  No range checking of arguments is carried out.
**
**  6)  In applications which involve many such calculations, rather
**      than calling the present function it will be more efficient to
**      use inline code, having previously computed fixed terms such
**      as sine and cosine of latitude, and (for tracking a star)
**      sine and cosine of declination.
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEarth ( int iy, int id, float fd, float pv[6] )
/*
**  - - - - - - - - -
**   s l a E a r t h
**  - - - - - - - - -
**
**  Approximate heliocentric position and velocity of the Earth.
**
**  (single precision)
**
**  Given:
**     iy       int        year
**     id       int        day in year (1 = Jan 1st)
**     fd       float      fraction of day
**
**  Returned:
**     pv       float[6]   Earth position & velocity vector
**
**  Notes:
**
**  1  The date and time is TDB (loosely ET) in a Julian calendar
**     which has been aligned to the ordinary Gregorian
**     calendar for the interval 1900 March 1 to 2100 February 28.
**     The year and day can be obtained by calling slaCalyd or
**     slaClyd.
**
**  2  The Earth heliocentric 6-vector is mean equator and equinox
**     of date.  Position part, PV(1-3), is in AU;  velocity part,
**     PV(4-6), is in AU/sec.
**
**  3  Max/RMS errors 1950-2050:
**       13/5 E-5 AU = 19200/7600 km in position
**       47/26 E-10 AU/s = 0.0070/0.0039 km/s in speed
**
**  4  More accurate results are obtainable with the functions slaEvp
**     and slaEpv.
**
**  Defined in slamac.h:  D2PI, dmod
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEcleq ( double dl, double db, double date,
                double *dr, double *dd)
/*
**  - - - - - - - - -
**   s l a E c l e q
**  - - - - - - - - -
**
**  Transformation from ecliptic coordinates to J2000.0
**  equatorial coordinates.
**
**  (double precision)
**
**  Given:
**     dl,db       double      ecliptic longitude and latitude
**                             (mean of date, IAU 1980 theory, radians)
**     date        double      TDB (loosely ET) as Modified Julian Date
**                                              (JD-2400000.5)
**  Returned:
**     *dr,*dd     double      J2000.0 mean RA,Dec (radians)
**
**  Called:
**     slaDcs2c, slaEcmat, slaDimxv, slaPrec, slaEpj, slaDcc2s,
**     slaDranrm, slaDrange
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEcmat ( double date, double rmat[3][3] )
/*
**  - - - - - - - - -
**   s l a E c m a t
**  - - - - - - - - -
**
**  Form the equatorial to ecliptic rotation matrix (IAU 1980 theory).
**
**  (double precision)
**
**  Given:
**     date     double         TDB (loosely ET) as Modified Julian Date
**                                            (JD-2400000.5)
**  Returned:
**     rmat     double[3][3]   matrix
**
**  References:
**     Murray, C.A., Vectorial Astrometry, section 4.3.
**
**  Note:
**    The matrix is in the sense   v[ecl]  =  rmat * v[equ];  the
**    equator, equinox and ecliptic are mean of date.
**
**  Called:  slaDeuler
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEcor ( float rm, float dm, int iy, int id, float fd,
               float *rv, float *tl )
/*
**  - - - - - - - -
**   s l a E c o r
**  - - - - - - - -
**
**  Component of Earth orbit velocity and heliocentric
**  light time in a given direction.
**
**  (single precision)
**
**  Given:
**     rm,dm    float    mean RA,Dec of date (radians)
**     iy       int      year
**     id       int      day in year (1 = Jan 1st)
**     fd       float    fraction of day
**
**  Returned:
**     *rv      float    component of Earth orbital velocity (km/sec)
**     *tl      float    component of heliocentric light time (sec)
**
**  Notes:
**
**  1  The date and time is TDB (loosely ET) in a Julian calendar
**     which has been aligned to the ordinary Gregorian
**     calendar for the interval 1900 March 1 to 2100 February 28.
**     The year and day can be obtained by calling slaCalyd or
**     slaClyd.
**
**  2  Sign convention:
**
**     The velocity component is +ve when the Earth is receding from
**     the given point on the sky.  The light time component is +ve
**     when the Earth lies between the Sun and the given point on
**     the sky.
**
**  3  Accuracy:
**
**     The velocity component is usually within 0.004 km/s of the
**     correct value and is never in error by more than 0.007 km/s.
**     The error in light time correction is about 0.03s at worst,
**     but is usually better than 0.01s. For applications requiring
**     higher accuracy, see the slaEvp and slaEpv functions.
**
**  Called:  slaEarth, slaCs2c, slaVdv
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEg50 ( double dr, double dd, double *dl, double *db )
/*
**  - - - - - - - -
**   s l a E g 5 0
**  - - - - - - - -
**
**  Transformation from B1950.0 'FK4' equatorial coordinates to
**  IAU 1958 Galactic coordinates.
**
**  (double precision)
**
**  Given:
**     dr,dd       double       B1950.0 'FK4' RA,dec
**
**  Returned:
**     *dl,*db     double       Galactic longitude and latitude l2,b2
**
**  (all arguments are radians)
**
**  Called:
**     slaDcs2c, slaDmxv, slaDcc2s, slaSubet, slaDranrm, slaDrange
**
**  Note:
**     The equatorial coordinates are B1950.0 'FK4'.  Use the
**     function slaEqgal if conversion from J2000.0 coordinates
**     is required.
**
**  Reference:
**     Blaauw et al., 1960, Mon.Not.R.astron.Soc., 121, 123
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEl2ue ( double date, int jform, double epoch, double orbinc,
                double anode, double perih, double aorq, double e,
                double aorl, double dm, double u[], int *jstat )
/*
**  - - - - - - - - -
**   s l a E l 2 u e
**  - - - - - - - - -
**
**  Transform conventional osculating orbital elements into "universal"
**  form.
**
**  Given:
**     date    double     epoch (TT MJD) of osculation (Note 3)
**     jform   int        choice of element set (1-3, Note 6)
**     epoch   double     epoch (TT MJD) of the elements
**     orbinc  double     inclination (radians)
**     anode   double     longitude of the ascending node (radians)
**     perih   double     longitude or argument of perihelion (radians)
**     aorq    double     mean distance or perihelion distance (AU)
**     e       double     eccentricity
**     aorl    double     mean anomaly or longitude (radians, jform=1,2 only)
**     dm      double     daily motion (radians, jform=1 only)
**
**  Returned:
**     u       double[13] universal orbital elements (Note 1)
**
**                    [0] combined mass (M+m)
**                    [1] total energy of the orbit (alpha)
**                    [2] reference (osculating) epoch (t0)
**                  [3-5] position at reference epoch (r0)
**                  [6-8] velocity at reference epoch (v0)
**                    [9] heliocentric distance at reference epoch
**                   [10] r0.v0
**                   [11] date (t)
**                   [12] universal eccentric anomaly (psi) of date, approx
**
**     jstat   int*       status:  0 = OK
**                                -1 = illegal jform
**                                -2 = illegal e
**                                -3 = illegal aorq
**                                -4 = illegal dm
**                                -5 = numerical error
**
**  Called:  slaUe2pv, slaPv2ue
**
**  Notes
**
**  1  The "universal" elements are those which define the orbit for the
**     purposes of the method of universal variables (see reference).
**     They consist of the combined mass of the two bodies, an epoch,
**     and the position and velocity vectors (arbitrary reference frame)
**     at that epoch.  The parameter set used here includes also various
**     quantities that can, in fact, be derived from the other
**     information.  This approach is taken to avoiding unnecessary
**     computation and loss of accuracy.  The supplementary quantities
**     are (i) alpha, which is proportional to the total energy of the
**     orbit, (ii) the heliocentric distance at epoch, (iii) the
**     outwards component of the velocity at the given epoch, (iv) an
**     estimate of psi, the "universal eccentric anomaly" at a given
**     date and (v) that date.
**
**  2  The companion function is slaUe2pv.  This takes the set of
**     numbers that the present function outputs and uses them to derive
**     the object's position and velocity.  A single prediction requires
**     one call to the present function followed by one call to
**     slaUe2pv;  for convenience, the two calls are packaged as the
**     function slaPlanel.  Multiple predictions may be made by again
**     calling the present function once, but then calling slaUe2pv
**     multiple times, which is faster than multiple calls to slaPlanel.
**
**  3  date is the epoch of osculation.  It is in the TT timescale
**     (formerly Ephemeris Time, ET) and is a Modified Julian Date
**     (JD-2400000.5).
**
**  4  The supplied orbital elements are with respect to the J2000
**     ecliptic and equinox.  The position and velocity parameters
**     returned in the array u are with respect to the mean equator and
**     equinox of epoch J2000, and are for the perihelion prior to the
**     specified epoch.
**
**  5  The universal elements returned in the array u are in canonical
**     units (solar masses, AU and canonical days).
**
**  6  Three different element-format options are available:
**
**     Option jform=1, suitable for the major planets:
**
**     epoch  = epoch of elements (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = longitude of perihelion, curly pi (radians)
**     aorq   = mean distance, a (AU)
**     e      = eccentricity, e (range 0 to <1)
**     aorl   = mean longitude L (radians)
**     dm     = daily motion (radians)
**
**     Option jform=2, suitable for minor planets:
**
**     epoch  = epoch of elements (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = argument of perihelion, little omega (radians)
**     aorq   = mean distance, a (AU)
**     e      = eccentricity, e (range 0 to <1)
**     aorl   = mean anomaly M (radians)
**
**     Option jform=3, suitable for comets:
**
**     epoch  = epoch of perihelion (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = argument of perihelion, little omega (radians)
**     aorq   = perihelion distance, q (AU)
**     e      = eccentricity, e (range 0 to 10)
**
**  7  Unused elements (dm for jform=2, aorl and dm for jform=3) are
**     not accessed.
**
**  8  The algorithm was originally adapted from the EPHSLA program of
**     D.H.P.Jones (private communication, 1996).  The method is based on
**     Stumpff's Universal Variables.
**
**  Reference:  Everhart, E. & Pitkin, E.T., Am.J.Phys. 51, 712, 1983.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEo ( double date )
/*
**  - - - - - -
**   s l a E o
**  - - - - - -
**
**  Equation of the origins.
**
**  Given:
**     date    double     TDB Modified Julian Date
**
**  Returned:
**             double     the equation of the origins (radians)
**
**  Called:  slaPneqx, slaEors, slaS
**
**  Notes:
**
**  1)  The date is TDB as an MJD (=JD-2400000.5).  TT will do.
**
**  2)  The equation of the origins is the distance between the true
**      equinox and the celestial intermediate origin and, equivalently,
**      the difference between Earth rotation angle and Greenwich
**      apparent sidereal time (ERA-GST).  It comprises the precession
**      (since J2000.0) in right ascension plus the equation of the
**      equinoxes (including the small correction terms).
**
**  Reference:
**
**     Capitaine, N. & Wallace, P.T. 2006, A&A (submitted).
**
**  Last revision:   30 December 2005
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEors ( double rnpb[3][3], double s )
/*
**  - - - - - - - -
**   s l a E o r s
**  - - - - - - - -
**
**  Equation of the origins, given the classical NPB matrix and the
**  quantity s.
**
**  Given:
**     rnpb   double[3][3]  classical NPB matrix
**     s      double        the quantity s (the CIO locator)
**
**  Returned:
**            double        the equation of the origins (radians)
**
**  Notes:
**
**  1)  The equation of the origins is the distance between the true
**      equinox and the celestial intermediate origin and, equivalently,
**      the difference between Earth rotation angle and Greenwich
**      apparent sidereal time (ERA-GST).  It comprises the precession
**      (since J2000.0) in right ascension plus the equation of the
**      equinoxes (including the small correction terms).
**
**  2)  The algorithm is from Wallace & Capitaine (2006).
**
**  Reference:
**
**     Wallace, P.T. & Capitaine, N. 2006, A&A (submitted).
**
**  Last revision:   29 July 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEpb ( double date )
/*
**  - - - - - - -
**   s l a E p b
**  - - - - - - -
**
**  Conversion of Modified Julian Date to Besselian epoch.
**
**  (double precision)
**
**  Given:
**     date     double      Modified Julian Date (JD - 2400000.5)
**
**  The result is the Besselian epoch.
**
**  Reference:
**     Lieske,J.H., 1979. Astron. Astrophys.,73,282.
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEpb2d ( double epb )
/*
**  - - - - - - - - -
**   s l a E p b 2 d
**  - - - - - - - - -
**
**  Conversion of Besselian epoch to Modified Julian Date.
**
**  (double precision)
**
**  Given:
**     epb      double       Besselian epoch
**
**  The result is the Modified Julian Date (JD - 2400000.5).
**
**  Reference:
**     Lieske,J.H., 1979. Astron. Astrophys.,73,282.
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEpco ( char k0, char k, double e )
/*
**  - - - - - - - -
**   s l a E p c o
**  - - - - - - - -
**
**  Convert an epoch into the appropriate form - 'B' or 'J'.
**
**  Given:
**     k0    char        form of result:  'B'=Besselian, 'J'=Julian
**     k     char        form of given epoch:  'B' or 'J'
**     e     double      epoch
**
**  Called:  slaEpb, slaEpj2d, slaEpj, slaEpb2d
**
**  Notes:
**
**     1) The result is always either equal to or very close to
**        the given epoch e.  The function is required only in
**        applications where punctilious treatment of heterogeneous
**        mixtures of star positions is necessary.
**
**     2) k0 and k are not validated, and only their first characters
**        are used, interpreted as follows:
**
**        o  If k0 and k are the same the result is e.
**        o  If k0 is 'B' or 'b' and k isn't, the conversion is J to B.
**        o  In all other cases, the conversion is B to J.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEpj ( double date )
/*
**  - - - - - - -
**   s l a E p j
**  - - - - - - -
**
**  Conversion of Modified Julian Date to Julian epoch.
**
**  (double precision)
**
**  Given:
**     date     double      Modified Julian Date (JD - 2400000.5)
**
**  The result is the Julian epoch.
**
**  Reference:
**
**     Lieske,J.H., 1979. Astron. Astrophys.,73,282.
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEpj2d ( double epj )
/*
**  - - - - - - - - -
**   s l a E p j 2 d
**  - - - - - - - - -
**
**  Conversion of Julian epoch to Modified Julian Date.
**
**  (double precision)
**
**  Given:
**     epj      double       Julian epoch
**
**  The result is the Modified Julian Date (JD - 2400000.5).
**
**  Reference:
**     Lieske,J.H., 1979. Astron. Astrophys.,73,282.
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEpv ( double tdb,
              double dph[3], double dvh[3],
              double dpb[3], double dvb[3] )
/*
**  - - - - - - -
**   s l a E p v
**  - - - - - - -
**
**  Earth position and velocity, heliocentric and barycentric, with
**  respect to the Barycentric Celestial Reference System.
**
**  Given:
**     date    double       date, TDB Modified Julian Date (Note 1)
**
**  Returned:
**     ph      double[3]    heliocentric Earth position (AU)
**     vh      double[3]    heliocentric Earth velocity (AU,AU/day)
**     pb      double[3]    barycentric Earth position (AU)
**     vb      double[3]    barycentric Earth velocity (AU/day)
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT can be used
**     instead of TDB in most applications.
**
**  2) On return, the arrays ph, vh, pv, pb contain the following:
**
**        ph(1)    x       }
**        ph(2)    y       } heliocentric position, AU
**        ph(3)    z       }
**
**        vh(1)    xdot    }
**        vh(2)    ydot    } heliocentric velocity, AU/d
**        vh(3)    zdot    }
**
**        pb(1)    x       }
**        pb(2)    y       } barycentric position, AU
**        pb(3)    z       }
**
**        vb(1)    xdot    }
**        vb(2)    ydot    } barycentric velocity, AU/d
**        vb(3)    zdot    }
**
**     The vectors are with respect to the Barycentric Celestial
**     Reference System (BCRS); velocities are in AU per TDB day.
**
**  3) The function is a SIMPLIFIED SOLUTION from the planetary theory
**     VSOP2000 (X. Moisson, P. Bretagnon, "Analytical Planetary
**     solution VSOP2000", Celestial Mechanics and Dynamical Astronomy,
**     vol. 80, Issue 3/4, pp 205-213, 2001) and is an adaptation of
**     original Fortran code supplied by P. Bretagnon (private
**     communication, 2000).
**
**  4) Comparisons over the time span 1900-2100 with this simplified
**     solution and the JPL DE405 ephemeris give the following results:
**
**                                RMS    max
**           Heliocentric:
**              position error    3.7   11.2   km
**              velocity error    1.4    5.0   mm/s
**
**           Barycentric:
**              position error    4.6   13.4   km
**              velocity error    1.4    4.9   mm/s
**
**     The results deteriorate outside this time span.
**
**  5) The function slaEvp is faster but less accurate.  The present
**     function targets the case where high accuracy is more important
**     than CPU time, yet the extra complication of reading a pre-
**     computed ephemeris is not justified.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
**
*/


void slaEqecl ( double dr, double dd, double date,
                double *dl, double *db )
/*
**  - - - - - - - - -
**   s l a E q e c l
**  - - - - - - - - -
**
**  Transformation from J2000.0 equatorial coordinates to
**  ecliptic coordinates.
**
**  (double precision)
**
**  Given:
**     dr,dd       double      J2000.0 mean RA,Dec (radians)
**     date        double      TDB (loosely ET) as Modified Julian Date
**                                              (JD-2400000.5)
**  Returned:
**     *dl,*db     double      ecliptic longitude and latitude
**                             (mean of date, IAU 1980 theory, radians)
**
**
**  Called:
**     slaDcs2c, slaPrec, slaEpj, slaDmxv, slaEcmat, slaDcc2s,
**     slaDranrm, slaDrange
**
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEqeqx ( double date )
/*
**  - - - - - - - - -
**   s l a E q e q x
**  - - - - - - - - -
**
**  Equation of the equinoxes (IAU 1994, double precision).
**
**  Given:
**     date    double      TDB (loosely ET) as Modified Julian Date
**                                          (JD-2400000.5)
**
**  The result is the equation of the equinoxes (double precision)
**  in radians:
**
**  Greenwich apparent ST = Greenwich mean ST + equation of the equinoxes
**
**  References:  IAU Resolution C7, Recommendation 3 (1994)
**               Capitaine, N. & Gontier, A.-M., Astron. Astrophys.,
**               275, 645-650 (1993)
**
**  Called:  slaNutc
**
**  Last revision:   21 November 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEqgal ( double dr, double dd, double *dl, double *db )
/*
**  - - - - - - - - -
**   s l a E q g a l
**  - - - - - - - - -
**
**  Transformation from J2000.0 equatorial coordinates to
**  IAU 1958 Galactic coordinates.
**
**  (double precision)
**
**  Given:
**     dr,dd       double       J2000.0 RA,Dec
**
**  Returned:
**     *dl,*db     double       Galactic longitude and latitude l2,b2
**
**  (all arguments are radians)
**
**  Called:
**     slaDcs2c, slaDmxv, slaDcc2s, slaDranrm, slaDrange
**
**  Note:
**     The equatorial coordinates are J2000.0.  Use the function
**     slaEg50 if conversion from B1950.0 'FK4' coordinates is
**     required.
**
**  Reference:
**     Blaauw et al., 1960, Mon.Not.R.astron.Soc., 121, 123
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaEra ( double date, double ut )
/*
**  - - - - - - -
**   s l a E r a
**  - - - - - - -
**
**  Earth rotation angle (IAU 2000 expression).
**
**  Given:
**    date   double    UT1 date (MJD: integer part of JD-2400000.5)
**    ut     double    UT1 time (fraction of a day)
**
**  The result is the Earth rotation angle (radians), in the range 0 to
**  2pi.
**
**  Notes:
**
**  1)  There is, in fact, no restriction on how the UT is apportioned
**      between the date and ut arguments.  Either of the two arguments
**      could, for example, be zero and the entire date+time supplied in
**      the other.  However, the function is designed to deliver maximum
**      accuracy when the date argument is a whole number and the ut
**      argument lies in the range 0 to 1, or vice versa.
**
**  2)  The algorithm is adapted from Expression 22 of Capitaine et al.
**      2000.  The time argument has been expressed in days directly,
**      and, to retain precision, integer contributions have been
**      eliminated at the earliest opportunity.
**
**  Defined in slamac.h:  D2PI
**
**  Called:  slaDranrm
**
**  Reference:
**     Capitaine N., Guinot B. and McCarthy D.D, 2000, A&A 355,
**     398-405.
**
**  Last revision:  22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEtrms ( double ep, double ev[3] )
/*
**  - - - - - - - - -
**   s l a E t r m s
**  - - - - - - - - -
**
**  Compute the e-terms (elliptic component of annual aberration)
**  vector.
**
**  (double precision)
**
**  Given:
**     ep      double      Besselian epoch
**
**  Returned:
**     ev      double[3]   e-terms as (dx,dy,dz)
**
**  References:
**
**     1  Smith, C.A. et al, 1989.  "The transformation of astrometric
**        catalog systems to the equinox J2000.0".  Astron.J. 97, 265.
**
**     2  Yallop, B.D. et al, 1989.  "Transformation of mean star places
**        from FK4 B1950.0 to FK5 J2000.0 using matrices in 6-space".
**        Astron.J. 97, 274.
**
**  Note the use of the J2000 aberration constant (20.49552 arcsec).
**  This is a reflection of the fact that the e-terms embodied in
**  existing star catalogues were computed from a variety of
**  aberration constants.  Rather than adopting one of the old
**  constants the latest value is used here.
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   7 November 2001
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEuler ( char *order, float phi, float theta, float psi,
                float rmat[3][3] )
/*
**  - - - - - - - - -
**   s l a E u l e r
**  - - - - - - - - -
**
**  Form a rotation matrix from the Euler angles - three successive
**  rotations about specified Cartesian axes.
**
**  (single precision)
**
**  Given:
**    *order  char         specifies about which axes the rotations occur
**    phi     float        1st rotation (radians)
**    theta   float        2nd rotation (   "   )
**    psi     float        3rd rotation (   "   )
**
**  Returned:
**    rmat   float[3][3]   rotation matrix
**
**  A rotation is positive when the reference frame rotates
**  anticlockwise as seen looking towards the origin from the
**  positive region of the specified axis.
**
**  The characters of order define which axes the three successive
**  rotations are about.  A typical value is 'ZXZ', indicating that
**  rmat is to become the direction cosine matrix corresponding to
**  rotations of the reference frame through phi radians about the
**  old z-axis, followed by theta radians about the resulting x-axis,
**  then psi radians about the resulting z-axis.
**
**  The axis names can be any of the following, in any order or
**  combination:  x, y, z, uppercase or lowercase, 1, 2, 3.  Normal
**  axis labelling/numbering conventions apply;  the xyz (=123)
**  triad is right-handed.  Thus, the 'ZXZ' example given above
**  could be written 'ZXZ' or '313' (or even 'zxz' or '3xz').  Order
**  is terminated by length or by the first unrecognized character.
**
**  Fewer than three rotations are acceptable, in which case the later
**  angle arguments are ignored.  Zero rotations leaves rmat set to the
**  identity matrix.
**
**  Called:  slaDeuler
**
**  Last revision:   9 December 1996
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaEvp ( double date, double deqx, double dvb[3], double dpb[3],
              double dvh[3], double dph[3] )
/*
**  - - - - - - -
**   s l a E v p
**  - - - - - - -
**
**  Barycentric and heliocentric velocity and position of the Earth.
**
**  Given:
**
**     date    double     TDB (loosely ET) as a Modified Julian Date
**                                         (JD-2400000.5)
**
**     deqx    double     Julian epoch (e.g. 2000.0) of mean equator and
**                        equinox of the vectors returned.  If deqx <= 0.0,
**                        all vectors are referred to the mean equator and
**                        equinox (FK5) of epoch date.
**
**  Returned (all 3D Cartesian vectors):
**
**     dvb,dpb double[3]  barycentric velocity, position (AU/s, AU)
**     dvh,dph double[3]  heliocentric velocity, position (AU/s, AU)
**
**  Called:  slaEpj, slaPrec
**
**  Notes:
**
**  1  This function is accurate enough for many purposes but faster and
**     more compact than the slaEpv function.  The maximum deviations
**     from the JPL DE96 ephemeris are as follows:
**
**       barycentric velocity         0.42  m/s
**       barycentric position         6900  km
**
**       heliocentric velocity        0.42  m/s
**       heliocentric position        1600  km
**
**  2  The function is adapted from the BARVEL and BARCOR subroutines of
**     Stumpff (1980).  Most of the changes are merely cosmetic and do
**     not affect the results at all.  However, some adjustments have
**     been made so as to give results that refer to the IAU 1976 'FK5'
**     equinox and precession, although the differences these changes
**     make relative to the results from Stumpff's original 'FK4'
**     version are smaller than the inherent accuracy of the algorithm.
**     One minor shortcoming in the original subroutine that has not
**     been corrected is that better numerical accuracy could be
**     achieved if the various polynomial evaluations were nested.
**
**  Reference:
**
**    Stumpff, P., 1980, Astron.Astrophys.Suppl.Ser. 41, 1-8
**
**  Defined in slamac.h:  D2PI, DS2R, dmod
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFitxy ( int itype, int np,
                double xye[][2], double xym[][2], double coeffs[6],
                int *j )
/*
**  - - - - - - - - -
**   s l a F i t x y
**  - - - - - - - - -
**
**  Fit a linear model to relate two sets of [x,y] coordinates.
**
**  Given:
**     itype    int            type of model: 4 or 6 (note 1)
**     np       int            number of samples (note 2)
**     xye      double[np][2]  expected [x,y] for each sample
**     xym      double[np][2]  measured [x,y] for each sample
**
**  Returned:
**     coeffs   double[6]      coefficients of model (note 3)
**     *j       int            status:  0 = OK
**                                     -1 = illegal itype
**                                     -2 = insufficient data
**                                     -3 = no solution
**
**  Notes:
**
**    1)  itype, which must be either 4 or 6, selects the type of model
**        fitted.  Both allowed itype values produce a model coeffs which
**        consists of six coefficients, namely the zero points and, for
**        each of xe and ye, the coefficient of xm and ym.  For itype=6,
**        all six coefficients are independent, modelling squash and shear
**        as well as origin, scale, and orientation.  However, itype=4
**        selects the "solid body rotation" option;  the model coeffs
**        still consists of the same six coefficients, but now two of
**        them are used twice (appropriately signed).  Origin, scale
**        and orientation are still modelled, but not squash or shear -
**        the units of x and y have to be the same.
**
**    2)  For nc=4, np must be at least 2.  For nc=6, np must be at
**        least 3.
**
**    3)  The model is returned in the array coeffs.  Naming the
**        elements of coeffs as follows:
**
**                    coeffs[0] = a
**                    coeffs[1] = b
**                    coeffs[2] = c
**                    coeffs[3] = d
**                    coeffs[4] = e
**                    coeffs[5] = f
**
**        The model is:
**
**              xe = a + b*xm + c*ym
**              ye = d + e*xm + f*ym
**
**        For the "solid body rotation" option (itype=4), the
**        magnitudes of b and f, and of c and e, are equal.  The
**        signs of these coefficients depend on whether there is a
**        sign reversal between xe,ye and xm,ym.  Fits are performed
**        with and without a sign reversal and the best one chosen.
**
**    4)  Error status values j=-1 and -2 leave coeffs unchanged;
**        If j=-3 coeffs may have been changed.
**
**  See also slaPxy, slaInvf, slaXy2xy, slaDcmpf
**
**  Called:  slaDmat, slaDmxv
**
**  Last revision:   7 September 2005
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFk425 ( double r1950, double d1950, double dr1950,
                double dd1950, double p1950, double v1950,
                double *r2000, double *d2000, double *dr2000,
                double *dd2000, double *p2000, double *v2000 )
/*
**  - - - - - - - - -
**   s l a F k 4 2 5
**  - - - - - - - - -
**
**  Convert B1950.0 FK4 star data to J2000.0 FK5.
**
**  (double precision)
**
**  This function converts stars from the old, Bessel-Newcomb, FK4
**  system to the new, IAU 1976, FK5, Fricke system.  The precepts
**  of Smith et al (Ref 1) are followed, using the implementation
**  by Yallop et al (Ref 2) of a matrix method due to Standish.
**  Kinoshita's development of Andoyer's post-Newcomb precession is
**  used.  The numerical constants from Seidelmann et al (Ref 3) are
**  used canonically.
**
**  Given:  (all B1950.0,FK4)
**
**     r1950,d1950     double    B1950.0 RA,dec (rad)
**     dr1950,dd1950   double    B1950.0 proper motions (rad/trop.yr)
**     p1950           double    parallax (arcsec)
**     v1950           double    radial velocity (km/s, +ve = moving away)
**
**  Returned:  (all J2000.0,FK5)
**
**     *r2000,*d2000   double    J2000.0 RA,dec (rad)
**     *dr2000,*dd2000 double    J2000.0 proper motions (rad/jul.yr)
**     *p2000          double    parallax (arcsec)
**     *v2000          double    radial velocity (km/s, +ve = moving away)
**
**  Notes:
**
**  1)  The proper motions in RA are dRA/dt rather than
**      cos(Dec)*dRA/dt, and are per year rather than per century.
**
**  2)  Conversion from Besselian epoch 1950.0 to Julian epoch
**      2000.0 only is provided for.  Conversions involving other
**      epochs will require use of the appropriate precession,
**      proper motion, and E-terms functions before and/or
**      after FK425 is called.
**
**  3)  In the FK4 catalogue the proper motions of stars within
**      10 degrees of the poles do not embody the differential
**      E-term effect and should, strictly speaking, be handled
**      in a different manner from stars outside these regions.
**      However, given the general lack of homogeneity of the star
**      data available for routine astrometry, the difficulties of
**      handling positions that may have been determined from
**      astrometric fields spanning the polar and non-polar regions,
**      the likelihood that the differential E-terms effect was not
**      taken into account when allowing for proper motion in past
**      astrometry, and the undesirability of a discontinuity in
**      the algorithm, the decision has been made in this function to
**      include the effect of differential E-terms on the proper
**      motions for all stars, whether polar or not.  At epoch 2000,
**      and measuring on the sky rather than in terms of dRA, the
**      errors resulting from this simplification are less than
**      1 milliarcsecond in position and 1 milliarcsecond per
**      century in proper motion.
**
**  References:
**
**     1  Smith, C.A. et al, 1989, "The transformation of astrometric
**        catalog systems to the equinox J2000.0", Astron.J. 97, 265
**
**     2  Yallop, B.D. et al, 1989, "Transformation of mean star places
**        from FK4 B1950.0 to FK5 J2000.0 using matrices in 6-space",
**        Astron.J. 97, 274
**
**     3  Seidelmann, P.K. (ed), 1992, "Explanatory Supplement to
**        the Astronomical Almanac", ISBN 0-935702-68-7
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFk45z ( double r1950, double d1950, double bepoch,
                double *r2000, double *d2000 )
/*
**  - - - - - - - - -
**   s l a F k 4 5 z
**  - - - - - - - - -
**
**  Convert B1950.0 FK4 star data to J2000.0 FK5 assuming zero
**  proper motion in the FK5 frame (double precision)
**
**  This function converts stars from the old, Bessel-Newcomb, FK4
**  system to the new, IAU 1976, FK5, Fricke system, in such a
**  way that the FK5 proper motion is zero.  Because such a star
**  has, in general, a non-zero proper motion in the FK4 system,
**  the function requires the epoch at which the position in the
**  FK4 system was determined.
**
**  The method is from Appendix 2 of Ref 1, but using the constants
**  of Ref 4.
**
**  Given:
**     r1950,d1950     double   B1950.0 FK4 RA,Dec at epoch (rad)
**     bepoch          double   Besselian epoch (e.g. 1979.3)
**
**  Returned:
**     *r2000,*d2000   double   J2000.0 FK5 RA,Dec (rad)
**
**  Notes:
**
**  1)  The epoch BEPOCH is strictly speaking Besselian, but
**      if a Julian epoch is supplied the result will be
**      affected only to a negligible extent.
**
**  2)  Conversion from Besselian epoch 1950.0 to Julian epoch
**      2000.0 only is provided for.  Conversions involving other
**      epochs will require use of the appropriate precession,
**      proper motion, and E-terms functions before and/or
**      after FK45Z is called.
**
**  3)  In the FK4 catalogue the proper motions of stars within
**      10 degrees of the poles do not embody the differential
**      E-term effect and should, strictly speaking, be handled
**      in a different manner from stars outside these regions.
**      However, given the general lack of homogeneity of the star
**      data available for routine astrometry, the difficulties of
**      handling positions that may have been determined from
**      astrometric fields spanning the polar and non-polar regions,
**      the likelihood that the differential E-terms effect was not
**      taken into account when allowing for proper motion in past
**      astrometry, and the undesirability of a discontinuity in
**      the algorithm, the decision has been made in this function to
**      include the effect of differential E-terms on the proper
**      motions for all stars, whether polar or not.  At epoch 2000,
**      and measuring on the sky rather than in terms of dRA, the
**      errors resulting from this simplification are less than
**      1 milliarcsecond in position and 1 milliarcsecond per
**      century in proper motion.
**
**  References:
**
**     1  Aoki,S., et al, 1983, Astron. Astrophys., 128, 263
**
**     2  Smith, C.A. et al, 1989, "The transformation of astrometric
**        catalog systems to the equinox J2000.0", Astron.J. 97, 265
**
**     3  Yallop, B.D. et al, 1989, "Transformation of mean star places
**        from FK4 B1950.0 to FK5 J2000.0 using matrices in 6-space",
**        Astron.J. 97, 274
**
**     4  Seidelmann, P.K. (ed), 1992, "Explanatory Supplement to
**        the Astronomical Almanac", ISBN 0-935702-68-7
**
**  Called:  slaDcs2c, slaEpj, slaEpb2d, slaDcc2s, slaDranrm
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFk524 ( double r2000, double d2000, double dr2000,
                double dd2000, double p2000, double v2000,
                double *r1950, double *d1950, double *dr1950,
                double *dd1950, double *p1950, double *v1950 )
/*
**  - - - - - - - - -
**   s l a F k 5 2 4
**  - - - - - - - - -
**
**  Convert J2000.0 FK5 star data to B1950.0 FK4.
**
**  (double precision)
**
**  This function converts stars from the new, IAU 1976, FK5, Fricke
**  system, to the old, Bessel-Newcomb, FK4 system.  The precepts
**  of Smith et al (Ref 1) are followed, using the implementation
**  by Yallop et al (Ref 2) of a matrix method due to Standish.
**  Kinoshita's development of Andoyer's post-Newcomb precession is
**  used.  The numerical constants from Seidelmann et al (Ref 3) are
**  used canonically.
**
**  Given:  (all J2000.0,FK5)
**     r2000,d2000      double    J2000.0 RA,Dec (rad)
**     dr2000,dd2000    double    J2000.0 proper motions (rad/Jul.yr)
**     p2000            double    parallax (arcsec)
**     v2000            double    radial velocity (km/s, +ve = moving away)
**
**  Returned:  (all B1950.0,FK4)
**     *r1950,*d1950    double    B1950.0 RA,Dec (rad)
**     *dr1950,*dd1950  double    B1950.0 proper motions (rad/trop.yr)
**     *p1950           double    parallax (arcsec)
**     *v1950           double    radial velocity (km/s, +ve = moving away)
**
**  Notes:
**
**  1)  The proper motions in RA are dRA/dt rather than
**      cos(Dec)*dRA/dt, and are per year rather than per century.
**
**  2)  Note that conversion from Julian epoch 2000.0 to Besselian
**      epoch 1950.0 only is provided for.  Conversions involving
**      other epochs will require use of the appropriate precession,
**      proper motion, and E-terms functions before and/or after
**      FK524 is called.
**
**  3)  In the FK4 catalogue the proper motions of stars within
**      10 degrees of the poles do not embody the differential
**      E-term effect and should, strictly speaking, be handled
**      in a different manner from stars outside these regions.
**      However, given the general lack of homogeneity of the star
**      data available for routine astrometry, the difficulties of
**      handling positions that may have been determined from
**      astrometric fields spanning the polar and non-polar regions,
**      the likelihood that the differential E-terms effect was not
**      taken into account when allowing for proper motion in past
**      astrometry, and the undesirability of a discontinuity in
**      the algorithm, the decision has been made in this function to
**      include the effect of differential E-terms on the proper
**      motions for all stars, whether polar or not.  At epoch 2000,
**      and measuring on the sky rather than in terms of dRA, the
**      errors resulting from this simplification are less than
**      1 milliarcsecond in position and 1 milliarcsecond per
**      century in proper motion.
**
**  References:
**
**     1  Smith, C.A. et al, 1989.  "The transformation of astrometric
**        catalog systems to the equinox J2000.0".  Astron.J. 97, 265.
**
**     2  Yallop, B.D. et al, 1989.  "Transformation of mean star places
**        from FK4 B1950.0 to FK5 J2000.0 using matrices in 6-space".
**        Astron.J. 97, 274.
**
**     3  Seidelmann, P.K. (ed), 1992.  "Explanatory Supplement to
**        the Astronomical Almanac", ISBN 0-935702-68-7.
**
**  Defined in slamac.h:  D2PI
**
**  Last revision:   22 October
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFk52h ( double r5, double d5, double dr5, double dd5,
                double *rh, double *dh, double *drh, double *ddh )
/*
**  - - - - - - - - -
**   s l a F k 5 2 h
**  - - - - - - - - -
**
**  Transform FK5 (J2000) star data into the Hipparcos frame.
**
**  (double precision)
**
**  This function transforms FK5 star positions and proper motions
**  into the frame of the Hipparcos catalogue.
**
**  Given (all FK5, equinox J2000, epoch J2000):
**     r5      double    RA (radians)
**     d5      double    Dec (radians)
**     dr5     double    proper motion in RA (dRA/dt, rad/Jyear)
**     dd5     double    proper motion in Dec (dDec/dt, rad/Jyear)
**
**  Returned (all Hipparcos, epoch J2000):
**     rh      double    RA (radians)
**     dh      double    Dec (radians)
**     drh     double    proper motion in RA (dRA/dt, rad/Jyear)
**     ddh     double    proper motion in Dec (dDec/dt, rad/Jyear)
**
**  Called:  slaDs2c6, slaDav2m, slaDmxv, slaDvxv, slaDc62s,
**           slaDranrm
**
**  Notes:
**
**  1)  The proper motions in RA are dRA/dt rather than
**      cos(Dec)*dRA/dt, and are per year rather than per century.
**
**  2)  The FK5 to Hipparcos transformation consists of a pure
**      rotation and spin;  zonal errors in the FK5 catalogue are
**      not taken into account.
**
**  3)  The published orientation and spin components are interpreted
**      as "axial vectors".  An axial vector points at the pole of the
**      rotation and its length is the amount of rotation in radians.
**
**  4)  See also slaH2fk5, slaFk5hz, slaHfk5z.
**
**  Reference:
**
**     M.Feissel & F.Mignard, 1998, Astron. Astrophys. 331, L33-L36
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFk54z ( double r2000, double d2000, double bepoch,
                double *r1950, double *d1950,
                double *dr1950, double *dd1950 )
/*
**  - - - - - - - - -
**   s l a F k 5 4 z
**  - - - - - - - - -
**
**  Convert a J2000.0 FK5 star position to B1950.0 FK4 assuming
**  zero proper motion and parallax.
**
**  This function converts star positions from the new, IAU 1976,
**  FK5, Fricke system to the old, Bessel-Newcomb, FK4 system.
**
**  Given:
**     r2000,d2000     double     J2000.0 FK5 RA,Dec (rad)
**     bepoch          double     Besselian epoch (e.g. 1950)
**
**  Returned:
**     *r1950,*d1950    double    B1950.0 FK4 RA,Dec (rad) at epoch BEPOCH
**     *dr1950,*dd1950  double    B1950.0 FK4 proper motions (rad/trop.yr)
**
**  Notes:
**
**  1)  The proper motion in RA is dRA/dt rather than cos(Dec)*dRA/dt.
**
**  2)  Conversion from Julian epoch 2000.0 to Besselian epoch 1950.0
**      only is provided for.  Conversions involving other epochs will
**      require use of the appropriate precession functions before and
**      after this function is called.
**
**  3)  Unlike in the slaFK524 function, the FK5 proper motions, the
**      parallax and the radial velocity are presumed zero.
**
**  4)  It is the intention that FK5 should be a close approximation
**      to an inertial frame, so that distant objects have zero proper
**      motion;  such objects have (in general) non-zero proper motion
**      in FK4, and this function returns those fictitious proper
**      motions.
**
**  5)  The position returned by this function is in the B1950
**      reference frame but at Besselian epoch bepoch.  For
**      comparison with catalogues the bepoch argument will
**      frequently be 1950.0.
**
**  Called:  slaFk524, slaPm
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFk5hz ( double r5, double d5, double epoch, double *rh, double *dh )
/*
**  - - - - - - - - -
**   s l a F k 5 h z
**  - - - - - - - - -
**
**  Transform an FK5 (J2000) star position into the frame of the
**  Hipparcos catalogue, assuming zero Hipparcos proper motion.
**
**  (double precision)
**
**  This function converts a star position from the FK5 system to
**  the Hipparcos system, in such a way that the Hipparcos proper
**  motion is zero.  Because such a star has, in general, a non-zero
**  proper motion in the FK5 system, the function requires the epoch
**  at which the position in the FK5 system was determined.
**
**  Given:
**     r5      double    FK5 RA (radians), equinox J2000, epoch EPOCH
**     d5      double    FK5 Dec (radians), equinox J2000, epoch EPOCH
**     epoch   double    Julian epoch (TDB)
**
**  Returned (all Hipparcos):
**     rh      double    RA (radians)
**     dh      double    Dec (radians)
**
**  Called:  slaDcs2c, slaDav2m, slaDimxv, slaDmxv, slaDcc2s, slaDranrm
**
**  Notes:
**
**  1)  The FK5 to Hipparcos transformation consists of a pure
**      rotation and spin;  zonal errors in the FK5 catalogue are
**      not taken into account.
**
**  2)  The published orientation and spin components are interpreted
**      as "axial vectors".  An axial vector points at the pole of the
**      rotation and its length is the amount of rotation in radians.
**
**  3)  See also slaFk52h, slaH2fk5, slaHfk5z.
**
**  Reference:
**
**     M.Feissel & F.Mignard, 1998, Astron. Astrophys. 331, L33-L36
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFlotin ( char *string, int *nstrt, float *reslt, int *jflag )
/*
**  - - - - - - - - - -
**   s l a F l o t i n
**  - - - - - - - - - -
**
**  Convert free-format input into single precision floating point.
**
**  Given:
**     *string      char      string containing field to be decoded
**     *nstrt       int       where to start decode (1st = 1)
**
**  Returned:
**     *nstrt       int        advanced to next field
**     *reslt       float      result
**     *jflag       int        -1 = -OK, 0 = +OK, 1 = null field, 2 = error
**
**  Called:  slaDfltin
**
**  Notes:
**
**     1     A tab character is interpreted as a space, and lower
**           case d,e are interpreted as upper case.
**
**     2     The basic format is #^.^@#^ where # means + or -,
**           ^ means a decimal subfield and @ means d or e.
**
**     3     Spaces:
**             Leading spaces are ignored.
**             Embedded spaces are allowed only after # and d or e,
**             and after . where the first ^ is absent.
**             Trailing spaces are ignored;  the first signifies
**             end of decoding and subsequent ones are skipped.
**
**     4     Field separators:
**             Any character other than +,-,0-9,.,d,e or space may be
**             used to end a field.  Comma is recognized by slaFlotin
**             as a special case; it is skipped, leaving the
**             pointer on the next character.  See 12, below.
**
**     5     Both signs are optional.  The default is +.
**
**     6     The mantissa defaults to 1.
**
**     7     The exponent defaults to e0.
**
**     8     The decimal subfields may be of any length.
**
**     9     The decimal point is optional for whole numbers.
**
**     10    A null field is one that does not begin with
**           +,-,0-9,.,d or e, or consists entirely of spaces.
**           If the field is null, jflag is set to 1 and reslt
**           is left untouched.
**
**     11    nstrt = 1 for the first character in the string.
**
**     12    On return from slaFlotin, nstrt is set ready for the next
**           decode - following trailing blanks and (if used) the
**           comma separator.  If a separator other than comma is
**           being used, nstrt must be incremented before the next
**           call to slaFlotin.
**
**     13    Errors (jflag=2) occur when:
**             a)  A +, -, d or e is left unsatisfied.
**             b)  The decimal point is present without at least
**                 one decimal subfield.
**             c)  An exponent more than 100 has been presented.
**
**     14    When an error has been detected, nstrt is left
**           pointing to the character following the last
**           one used before the error came to light.  This
**           may be after the point at which a more sophisticated
**           program could have detected the error.  For example,
**           slaFlotin does not detect that '1e999' is unacceptable
**           until the whole field has been read.
**
**     15    Certain highly unlikely combinations of mantissa &
**           exponent can cause arithmetic faults during the
**           decode, in some cases despite the fact that they
**           together could be construed as a valid number.
**
**     16    Decoding is left to right, one pass.
**
**     17    End of field may occur in either of two ways:
**             a)  As dictated by the string length.
**             b)  Detected during the decode.
**                 (b overrides a.)
**
**     18    See also slaDfltin, slaInt2in and slaIntin.
**
**  Last revision:   10 December 2002
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFw2m  ( double gamb, double phib, double psi, double eps,
                double r[3][3] )
/*
**  - - - - - - - -
**   s l a F w 2 m
**  - - - - - - - -
**
**  Form rotation matrix given the Fukushima-Williams angles.
**
**  Given:
**     gamb     double        F-W angle gamma_bar (radians)
**     phib     double        F-W angle phi_bar (radians)
**     psi      double        F-W angle psi (radians)
**     eps      double        F-W angle epsilon (radians)
**
**  Returned:
**     r        double[3][3]  rotation matrix
**
**  Notes:
**
**  1) Naming the following points:
**
**           e = J2000 ecliptic pole,
**           p = GCRS pole,
**           E = ecliptic pole of date,
**     and   P = CIP,
**
**     the four Fukushima-Williams angles are as follows:
**
**        gamb = gamma = epE
**        phib = phi = pE
**        psi = psi = pEP
**        eps = epsilon = EP
**
**  2) The matrix representing the combined effects of frame bias,
**     precession and nutation is:
**
**        NxPxB = R_1(-eps).R_3(-psi).R_1(phib).R_3(gamb)
**
**  3) Three different matrices can be constructed, depending on the
**     supplied angles:
**
**     . To obtain the nutation x precession x frame bias matrix,
**       generate the four precession angles, generate the nutation
**       components and add them to the psi_bar and epsilon_A angles,
**       and call the present function.
**
**     . To obtain the precession x frame bias matrix, generate the four
**       precession angles and call the present function.
**
**     . To obtain the frame bias matrix, generate the four precession
**       angles for date J2000.0 and call the present function.
**
**     The nutation-only and precession-only matrices can if necessary
**     be obtained by combining these three appropriately.
**
**  Reference:
**
**     Hilton, J. et al., 2006, Celest.Mech.Dyn.Astron. 94, 351
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaFw2xy ( double gamb, double phib, double psi, double eps,
                double *x, double *y )
/*
**  - - - - - - - - -
**   s l a F w 2 x y
**  - - - - - - - - -
**
**  CIP X,Y given Fukushima-Williams bias-precession-nutation angles.
**
**  Given:
**     gamb     double    F-W angle gamma_bar (radians)
**     phib     double    F-W angle phi_bar (radians)
**     psi      double    F-W angle psi (radians)
**     eps      double    F-W angle epsilon (radians)
**
**  Returned:
**     x,y      double*   CIP X,Y ("radians")
**
**  Notes:
**
**  1) Naming the following points:
**
**           e = J2000 ecliptic pole,
**           p = GCRS pole
**           E = ecliptic pole of date,
**     and   P = CIP,
**
**     the four Fukushima-Williams angles are as follows:
**
**        gamb = gamma = epE
**        phib = phi = pE
**        psi = psi = pEP
**        eps = epsilon = EP
**
**  2) The matrix representing the combined effects of frame bias,
**     precession and nutation is:
**
**        NxPxB = R_1(-epsa).R_3(-psi).R_1(phib).R_3(gamb)
**
**     X,Y are elements (3,1) and (3,2) of the matrix.
**
**  Reference:
**
**     Hilton, J. et al., 2006, Celest.Mech.Dyn.Astron. 94, 351
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaG2ixys ( double x, double y, double s, double rc2i[3][3] )
/*
**  - - - - - - - - - -
**   s l a G 2 i x y s
**  - - - - - - - - - -
**
**  Form the GCRS to CIRS matrix given the CIP X,Y and the CIO locator
**  s.
**
**  Given:
**     x,y    double        celestial intermediate pole (Note 1)
**     s      double        the quantity s (Note 2)
**
**  Returned:
**     rc2i   double[3][3]  GCRS-to-CIRS matrix (Note 3)
**
**  Notes:
**
**  1) The celestial intermediate pole coordinates are the x,y
**     components of the unit vector in the GCRS.
**
**  2) The quantity s (in radians) positions the celestial intermediate
**     origin on the equator of the CIP.
**
**  3) The matrix rc2i is the first stage in the transformation from
**     celestial to terrestrial coordinates:
**
**        [TRS]  =  RPOM * R_3(ERA) * RC2I * [CRS]
**
**     where [CRS] is a vector in the Geocentric Celestial Reference
**     System and [TRS] is a vector in the International Terrestrial
**     Reference System, ERA is the Earth rotation angle and RPOM is the
**     polar motion matrix.
**
**  Called:  slaDeuler
**
**  Reference:
**
**     McCarthy, D.D., Petit, G. (eds.) 2004, IERS Conventions (2003),
**     IERS Technical Note No. 32, BKG
**
**  Last revision:   7 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaGaleq ( double dl, double db, double *dr, double *dd )
/*
**  - - - - - - - - -
**   s l a G a l e q
**  - - - - - - - - -
**
**  Transformation from IAU 1958 Galactic coordinates to
**  J2000.0 equatorial coordinates.
**
**  (double precision)
**
**  Given:
**     dl,db       double      galactic longitude and latitude l2,b2
**
**  Returned:
**     *dr,*dd     double      J2000.0 RA,dec
**
**  (all arguments are radians)
**
**  Called:
**     slaDcs2c, slaDimxv, slaDcc2s, slaDranrm, slaDrange
**
**  Note:
**     The equatorial coordinates are J2000.0.  Use the function
**     slaGe50 if conversion to B1950.0 'FK4' coordinates is
**     required.
**
**  Reference:
**     Blaauw et al., 1960, Mon.Not.R.astron.Soc., 121, 123
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaGalsup ( double dl, double db, double *dsl, double *dsb )
/*
**  - - - - - - - - - -
**   s l a G a l s u p
**  - - - - - - - - - -
**
**  Transformation from IAU 1958 Galactic coordinates to
**  De Vaucouleurs supergalactic coordinates.
**
**  (double precision)
**
**  Given:
**     dl,db       double       Galactic longitude and latitude l2,b2
**
**  Returned:
**     *dsl,*dsb   double       Supergalactic longitude and latitude
**
**  (all arguments are radians)
**
**  Called:
**     slaDcs2c, slaDmxv, slaDcc2s, slaDranrm, slaDrange
**
**  References:
**
**     De Vaucouleurs, De Vaucouleurs, & Corwin, Second reference
**     catalogue of bright galaxies, U. Texas, page 8.
**
**     Systems & Applied Sciences Corp., Documentation for the
**     machine-readable version of the above catalogue,
**     contract NAS 5-26490.
**
**    (These two references give different values for the Galactic
**     longitude of the Supergalactic origin.  Both are wrong;  the
**     correct value is l2 = 137.37.)
**
**  Last revision:   25 January 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaGe50 ( double dl, double db, double *dr, double *dd )
/*
**  - - - - - - - -
**   s l a G e 5 0
**  - - - - - - - -
**
**  Transformation from IAU 1958 Galactic coordinates to
**  B1950.0 'FK4' equatorial coordinates.
**
**  (double precision)
**
**  Given:
**     dl,db       double       Galactic longitude and latitude l2,b2
**
**  Returned:
**     *dr,*dd     double       B1950.0 'FK4' RA,Dec
**
**  (all arguments are radians)
**
**  Called:
**     slaDcs2c, slaDimxv, slaDcc2s, slaAddet, slaDranrm, slaDrange
**
**  Note:
**     The equatorial coordinates are B1950.0 'FK4'.  Use the
**     function slaGaleq if conversion to J2000.0 coordinates
**     is required.
**
**  Reference:
**     Blaauw et al., 1960, Mon.Not.R.astron.Soc., 121, 123
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaGeoc ( double p, double h, double *r, double *z )
/*
**  - - - - - - - -
**   s l a G e o c
**  - - - - - - - -
**
**  Convert geodetic position to geocentric.
**
**  (double precision)
**
**  Given:
**     p     double     latitude (geodetic, radians)
**     h     double     height above reference spheroid (geodetic, metres)
**
**  Returned:
**     *r    double     distance from Earth axis (AU)
**     *z    double     distance from plane of Earth equator (AU)
**
**  Notes:
**
**  1  Geocentric latitude can be obtained by evaluating atan2(z,r).
**
**  2  IAU 1976 constants are used.
**
**  Reference:
**
**     Green,R.M., Spherical Astronomy, CUP 1985, p98.
**
**  Last revision:   22 July 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaGmst ( double ut1 )
/*
**  - - - - - - - -
**   s l a G m s t
**  - - - - - - - -
**
**  Conversion from Universal Time to Sidereal Time.
**
**  (double precision)
**
**  Given:
**    ut1    double     Universal Time (strictly UT1) expressed as
**                      Modified Julian Date (JD-2400000.5)
**
**  The result is the Greenwich Mean Sidereal Time (double
**  precision, radians).
**
**  The IAU 1982 expression (see page S15 of 1984 Astronomical Almanac)
**  is used, but rearranged to reduce rounding errors.  This expression
**  is always described as giving the GMST at 0 hours UT.  In fact, it
**  gives the difference between the GMST and the UT, which happens to
**  equal the GMST (modulo 24 hours) at 0 hours UT each day.  In this
**  function, the entire UT is used directly as the argument for the
**  standard formula, and the fractional part of the UT is added
**  separately.  Note that the factor 1.0027379... does not appear in
**  the IAU 1982 expression explicitly but in the form of the
**  coefficient 8640184.812866, which is 86400x36525x0.0027379...
**
**  See also the function slaGmsta, which delivers better numerical
**  precision by accepting the UT date and time as separate arguments.
**
**  Called:  slaDranrm
**
**  Defined in slamac.h:  D2PI, DS2R, dmod
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaGmsta ( double date, double ut )
/*
**  - - - - - - - - -
**   s l a G m s t a
**  - - - - - - - - -
**
**  Conversion from Universal Time to Greenwich mean sidereal time,
**  with rounding errors minimized.
**
**  (double precision)
**
**  Given:
**    date   double     UT1 date (MJD: integer part of JD-2400000.5)
**    ut     double     UT1 time (fraction of a day)
**
**  The result is the Greenwich Mean Sidereal Time (double precision,
**  radians, in the range 0 to 2pi).
**
**  There is no restriction on how the UT is apportioned between the
**  date and ut1 arguments.  Either of the two arguments could, for
**  example, be zero and the entire date+time supplied in the other.
**  However, the function is designed to deliver maximum accuracy when
**  the date argument is a whole number and the ut argument lies in
**  the range 0 to 1, or vice versa.
**
**  The algorithm is based on the IAU 1982 expression (see page S15 of
**  the 1984 Astronomical Almanac).  This is always described as giving
**  the GMST at 0 hours UT1.  In fact, it gives the difference between
**  the GMST and the UT, the steady 4-minutes-per-day drawing-ahead of
**  ST with respect to UT.  When whole days are ignored, the expression
**  happens to equal the GMST at 0 hours UT1 each day.  Note that the
**  factor 1.0027379... does not appear explicitly but in the form of
**  the coefficient 8640184.812866, which is 86400x36525x0.0027379...
**
**  In this function, the entire UT1 (the sum of the two arguments date
**  and ut) is used directly as the argument for the standard formula.
**  The UT1 is then added, but omitting whole days to conserve accuracy.
**
**  See also the function slaGmst, which accepts the UT1 as a single
**  argument.  Compared with slaGmst, the extra numerical precision
**  delivered by the present function is unlikely to be important in
**  an absolute sense, but may be useful when critically comparing
**  algorithms and in applications where two sidereal times close
**  together are differenced.
**
**  Called:  slaDranrm
**
**  Defined in slamac.h:  DS2R, dmod
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaGst ( double date, double utdate, double ut )
/*
**  - - - - - - -
**   s l a G s t
**  - - - - - - -
**
**  Greenwich (apparent) sidereal time, from ERA and EO.
**
**  Given:
**    date    double    TDB Modified Julian Date
**    utdate  double    UT1 date (MJD: integer part of JD-2400000.5)
**    ut      double    UT1 time (fraction of a day)
**
**  Returned:
**            double    Greenwich apparent sidereal time (radians, in
**                      the range 0 to 2pi).
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT will do.
**
**  2) This Greenwich sidereal time is consistent with the latest and
**     most accurate of SLALIB's precession-nutation models.  It does
**     not use the conventional GMST formula and equation of the
**     equinoxes, but instead computes GST directly from the Earth
**     rotation angle and the equation of the origins (the distance
**     between the true equinox of date and the celestial intermediate
**     origin).
**
**  3) There is no restriction on how the UT is apportioned between the
**     utdate and ut arguments.  Either of the two arguments could, for
**     example, be zero and the entire date+time supplied in the other.
**     However, the function is designed to deliver maximum accuracy
**     when the utdate argument is a whole number and ut lies in the
**     range 0 to 1 (or vice versa).
**
**  Called:  slaDranrm
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaH2e ( float az, float el, float phi, float *ha, float *dec )
/*
**  - - - - - - -
**   s l a H 2 e
**  - - - - - - -
**
**  Horizon to equatorial coordinates:  Az,El to HA,Dec
**
**  (single precision)
**
**  Given:
**     az          float       azimuth
**     el          float       elevation
**     phi         float       observatory latitude
**
**  Returned:
**     *ha         float       hour angle
**     *dec        float       declination
**
**  Notes:
**
**  1)  All the arguments are angles in radians.
**
**  2)  The sign convention for azimuth is north zero, east +pi/2.
**
**  3)  HA is returned in the range +/-pi.  Declination is returned
**      in the range +/-pi/2.
**
**  4)  The latitude is (in principle) geodetic.  In critical
**      applications, corrections for polar motion should be applied.
**
**  5)  In some applications it will be important to specify the
**      correct type of elevation in order to produce the required
**      type of HA,Dec.  In particular, it may be important to
**      distinguish between the elevation as affected by refraction,
**      which will yield the "observed" HA,Dec, and the elevation
**      in vacuo, which will yield the "topocentric" HA,Dec.  If the
**      effects of diurnal aberration can be neglected, the
**      topocentric HA,Dec may be used as an approximation to the
**      "apparent" HA,Dec.
**
**  6)  No range checking of arguments is done.
**
**  7)  In applications which involve many such calculations, rather
**      than calling the present function it will be more efficient to
**      use inline code, having previously computed fixed terms such
**      as sine and cosine of latitude.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaH2fk5 ( double rh, double dh, double drh, double ddh,
                double *r5, double *d5, double *dr5, double *dd5 )
/*
**  - - - - - - - - -
**   s l a H 2 f k 5
**  - - - - - - - - -
**
**  Transform Hipparcos star data into the FK5 (J2000) system.
**
**  (double precision)
**
**  This function transforms Hipparcos star positions and proper
**  motions into FK5 J2000.
**
**  Given (all Hipparcos, epoch J2000):
**     rh      double    RA (radians)
**     dh      double    Dec (radians)
**     drh     double    proper motion in RA (dRA/dt, rad/Jyear)
**     ddh     double    proper motion in Dec (dDec/dt, rad/Jyear)
**
**  Returned (all FK5, equinox J2000, Epoch J2000):
**     r5      double    RA (radians)
**     d5      double    Dec (radians)
**     dr5     double    proper motion in RA (dRA/dt, rad/Jyear)
**     dd5     double    proper motion in Dec (dDec/dt, rad/Jyear)
**
**  Called:  slaDs2c6, slaDav2m, slaDmxv, slaDimxv, slaDvxv,
**           slaDc62s, slaDranrm
**
**  Notes:
**
**  1)  The proper motions in RA are dRA/dt rather than
**      cos(Dec)*dRA/dt, and are per year rather than per century.
**
**  2)  The FK5 to Hipparcos transformation consists of a pure
**      rotation and spin;  zonal errors in the FK5 catalogue are
**      not taken into account.
**
**  3)  The published orientation and spin components are interpreted
**      as "axial vectors".  An axial vector points at the pole of the
**      rotation and its length is the amount of rotation in radians.
**
**  4)  See also slaFk52h, slaFk5hz, slaHfk5z.
**
**  Reference:
**
**     M.Feissel & F.Mignard, Astron. Astrophys. 331, L33-L36 (1998).
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaHfk5z ( double rh, double dh, double epoch,
                double *r5, double *d5, double *dr5, double *dd5 )
/*
**  - - - - - - - - -
**   s l a H f k 5 z
**  - - - - - - - - -
**
**  Transform a Hipparcos star position into FK5 J2000, assuming
**  zero Hipparcos proper motion.
**
**  (double precision)
**
**  Given:
**     rh      double    Hipparcos RA (radians)
**     dh      double    Hipparcos Dec (radians)
**     epoch   double    Julian epoch (TDB)
**
**  Returned (all FK5, equinox J2000, epoch EPOCH):
**     r5      double    RA (radians)
**     d5      double    Dec (radians)
**
**  Called:  slaDcs2c, slaDav2m, slaDmxv, slaDav2m, slaDmxm,
**           slaDimxv, slaDvxv, slaDc62s, slaDranrm
**
**  Notes:
**
**  1)  The proper motion in RA is dRA/dt rather than cos(Dec)*dRA/dt.
**
**  2)  The FK5 to Hipparcos transformation consists of a pure
**      rotation and spin;  zonal errors in the FK5 catalogue are
**      not taken into account.
**
**  3)  The published orientation and spin components are interpreted
**      as "axial vectors".  An axial vector points at the pole of the
**      rotation and its length is the amount of rotation in radians.
**
**  4)  It was the intention that Hipparcos should be a close
**      approximation to an inertial frame, so that distant objects
**      have zero proper motion;  such objects have (in general)
**      non-zero proper motion in FK5, and this function returns those
**      fictitious proper motions.
**
**  5)  The position returned by this function is in the FK5 J2000
**      reference frame but at the specified epoch.
**
**  6)  See also slaFk52h, slaH2fk5, slaFk5zhz.
**
**  Reference:
**
**     M.Feissel & F.Mignard, Astron. Astrophys. 331, L33-L36 (1998).
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaI2c ( double ri, double di, double date, double dx, double dy,
              double *rc, double *dc )
/*
**  - - - - - - -
**   s l a I 2 c
**  - - - - - - -
**
**  Transform star RA,Dec from CIRS to ICRS astrometric.
**
**  Given:
**     ri,di     double    CIRS RA,Dec (radians)
**     date      double    TDB (JD-2400000.5)
**     dx,dy     double    corrections to IAU 2000A CIP X,Y (radians)
**
**  Returned:
**     rc,dc     double*   ICRS astrometric RA,Dec (radians)
**
**  Notes:
**
**  1)  The distinction between the required TDB and TT is always
**      negligible.  Moreover, for all but the most critical
**      applications UTC is adequate.
**
**  2)  Iterative techniques are used for the aberration and light
**      deflection corrections so that the functions slaI2c (or
**      slaI2cqk) and slaC2i (or slaC2iqk) are accurate inverses; even
**      at the edge of the Sun's disc the discrepancy is only about
**      1 nanoarcsecond.
**
**  3)  Where multiple CIRS RA,Decs are to be transformed into
**      astrometric places, for a fixed date, it is more efficient to
**      use the slaC2ipa function to compute the required parameters
**      once, followed by one call to slaI2cqk per star.
**
**  4)  The accuracy is sub-milliarcsecond, limited by the precession-
**      nutation information (IAU 2006 model plus the CIP corrections,
**      which are obtained from IERS bulletins).
**
**  5)  The accuracy is in principle further limited by the function
**      slaEpv, called by slaC2ipa, which computes the Earth position
**      and velocity.  The maximum error arising from this source is
**      less than 5 microarcseconds.
**
**  Reference:
**
**     Explanatory Supplement to the Astronomical Ephemeris, Chapter 3.
**
**  Called:  slaC2ipa, slaI2cqk
**
**  This revision:   17 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaI2cqk ( double ri, double di, CIpars *ciprms,
                double *rc, double *dc )
/*
**  - - - - - - - - -
**   s l a I 2 c q k
**  - - - - - - - - -
**
**  Quick CIRS RA,Dec to ICRS astrometric place, given the star-
**  independent parameters.
**
**  Use of this function is appropriate when efficiency is important and
**  where many star positions are all to be transformed for one date.
**  The star-independent parameters can be obtained by calling the
**  slaC2ipa function.
**
**  Given:
**     ri,di     double    CIRS RA,Dec (radians)
**     ciprms    CIpars*   star-independent ICRS-to-CIRS parameters:
**      pmt        double    time interval for proper motion (Jyears)
**      eb[3]      double    SSB to Earth (AU)
**      ehn[3]     double    Sun to Earth unit vector
**      gr2e       double    (grav rad Sun)*2/(Sun-Earth distance)
**      abv[3]     double    barycentric Earth velocity in units of c
**      ab1        double    sqrt(1-v**2) where v=modulus(abv)
**      bpn[3][3]  double    bias-precession-nutation matrix
**
**  Returned:
**     rc,dc     double*   ICRS astrometric RA,Dec (radians)
**
**  Note:
**
**     Iterative techniques are used for the aberration and light
**     deflection corrections so that the functions slaI2c (or slaI2cqk)
**     and slaC2i (or slaC2iqk) are accurate inverses;  even at the edge
**     of the Sun's disc the discrepancy is only about 1 nanoarcsecond.
**
**  Reference:
**     Explanatory Supplement to the Astronomical Ephemeris, Chapter 3.
**
**  Called:  slaDcs2c, slaDimxv, slaDvdv, slaDvn, slaDcc2s, slaDranrm
**
**  This revision:   17 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaI2o ( double ri, double di, double date, double dut,
              double elong, double phi, double hm, double xp, double yp,
              double tk, double pmb, double rh, double wl, double tlr,
              double *aob, double *zob, double *hob,
              double *dob, double *rob )
/*
**  - - - - - - -
**   s l a I 2 o
**  - - - - - - -
**
**  CIRS RA,Dec to observed place at a ground based site, for sources
**  distant from the solar system.
**
**  Given:
**     ri    double   CIRS right ascension (CEO-based, radians)
**     di    double   CIRS declination (radians)
**     date  double   UTC date/time (Modified Julian Date, JD-2400000.5)
**     dut   double   delta UT:  UT1-UTC (UTC seconds)
**     elong double   longitude of the observer (radians, east +ve)
**     phi   double   geodetic latitude of the observer (radians)
**     hm    double   observer's height above sea level (metres)
**     xp    double   polar motion x-coordinate (radians)
**     yp    double   polar motion y-coordinate (radians)
**     tk    double   local ambient temperature (K; std=273.15)
**     pmb   double   local atmospheric pressure (mb; std=1013.25)
**     rh    double   local relative humidity (in the range 0-1)
**     wl    double   effective wavelength (micron, e.g. 0.55)
**     tlr   double   tropospheric lapse rate (K/metre, e.g. 0.0065)
**
**  Returned:
**     aob   double*  observed azimuth (radians: N=0,E=90)
**     zob   double*  observed zenith distance (radians)
**     hob   double*  observed hour angle (radians)
**     dob   double*  observed declination (radians)
**     rob   double*  observed right ascension (CEO-based, radians)
**
**  Notes:
**
**   1) This function returns zenith distance rather than elevation
**      in order to reflect the fact that no allowance is made for
**      depression of the horizon.
**
**   2) The accuracy of the result is limited by the corrections for
**      refraction.  Providing the meteorological parameters are
**      known accurately and there are no gross local effects, the
**      predicted observed RA,Dec should be within about 0.1 arcsec
**      for a zenith distance of less than 70 degrees.  Even at a
**      topocentric zenith distance of 90 degrees, the accuracy in
**      elevation should be better than 1 arcmin;  useful results
**      are available for a further 3 degrees, beyond which the
**      slaRefro function returns a fixed value of the refraction.
**      The complementary functions slaI2o (or slaI2oqk) and slaO2i
**      (or slaO2iqk) are self-consistent to better than 1 micro-
**      arcsecond all over the celestial sphere.
**
**   3) It is advisable to take great care with units, as even
**      unlikely values of the input parameters are accepted and
**      processed in accordance with the models used.
**
**   4) The CIRS RA,Dec is obtained from a star catalogue mean place by
**      allowing for space motion, parallax, the Sun's gravitational
**      lens effect, annual aberration and precession-nutation.  For
**      star positions in the ICRS, these effects can be applied by
**      means of the slaC2i etc. functions.  Starting from the
**      formerly used "mean place" systems, additional transformations
**      will be needed first.
**
**   5) "Observed" Az,ZD means the position that would be seen by a
**      perfect theodolite located at the observer.  This is obtained
**      from the CIRS RA,Dec by allowing for Earth orientation and
**      diurnal aberration, rotating from equator to horizon
**      coordinates, and then adjusting for refraction.  The HA,Dec is
**      obtained by rotating back into equatorial coordinates, and is
**      the position that would be seen by a perfect equatorial located
**      at the observer and with its polar axis aligned to the Earth's
**      axis of rotation (n.b. not to the refracted pole).  Finally,
**      the RA is obtained by subtracting the HA from the local ERA.
**
**   6) To predict the required setting of a real telescope, the
**      observed place produced by this function would have to be
**      adjusted for the tilt of the azimuth or polar axis of the
**      mounting (with appropriate corrections for mount flexures),
**      for the non-perpendicularities between the two mount axes and
**      between the reference pointing axis and the mount declination
**      or elevation axis, for the desired image location in the focal
**      plane, for tube flexure, for gear and encoder errors, and
**      finally for encoder zero points.  Some telescopes would, of
**      course, exhibit other properties which would need to be
**      accounted for at the appropriate point in the sequence.
**
**   7) This function takes time to execute, due mainly to the
**      rigorous ray-trace integration used to evaluate the refraction.
**      For processing multiple stars for one location and time, call
**      slaI2opa once followed by one call per star to slaI2oqk.
**      Where a range of times within a limited period of a few hours
**      is involved, and the highest precision is not required, call
**      slaI2opa once, followed by a call to slaI2opat each time the
**      time changes, followed by one call per star to slaI2oqk.
**
**   8) The date argument is UTC expressed as an MJD.  This is,
**      strictly speaking, improper, because of leap seconds.  However,
**      as long as the delta UT and the UTC are consistent there are no
**      difficulties, except during a leap second.  In this case, the
**      start of the 61st second of the final minute should begin a new
**      MJD day and the old pre-leap delta UT should continue to be
**      used.  As the 61st second completes, the MJD should revert to
**      the start of the day as, simultaneously, the delta UTC changes
**      by one second to its post-leap new value.
**
**   9) The delta UT (UT1-UTC) is tabulated in IERS bulletins.  It
**      increases by exactly one second at the end of each UTC leap
**      second, introduced in order to keep delta UT within +/- 0.9s.
**
**  10) IMPORTANT -- TAKE CARE WITH THE LONGITUDE SIGN CONVENTION.
**      The longitude required by the present function is east-positive,
**      in accordance with geographical convention (and right-handed).
**      In particular, note that the longitudes returned by the
**      slaObs function are west-positive, following astronomical
**      usage, and must be reversed in sign before use in the present
**      function.
**
**  11) The polar motion coordinates xp,yp can be obtained from IERS
**      bulletins.  The maximum amplitude is about 0.3 arcseconds.  If
**      xp,yp values are unavailable, use zeroes.  The xp,yp
**      coordinates are reckoned as follows:
**
**      . +ve xp means that the point on the geoid directly beneath
**        the CIP is in the hemisphere centered on longitude 90 deg.
**
**      . +ve yp means that the point on the geoid directly beneath
**        the CIP is in the hemisphere centered on longitude 270 deg.
**
**      Internally, the polar motion is stored in a form rotated onto
**      the local meridian.
**
**  12) The height above sea level of the observing station, hm,
**      can be obtained from the Astronomical Almanac (Section J
**      in the 1988 edition), or via the function slaObs.  If p,
**      the pressure in millibars, is available, an adequate
**      estimate of hm can be obtained from the expression
**
**            hm = -29.3 * tsl * log ( p / 1013.25 );
**
**      where tsl is the approximate sea-level air temperature in K
**      (See Astrophysical Quantities, C.W.Allen, 3rd edition, section
**      52).  Similarly, if the pressure p is not known, it can be
**      estimated from the height of the observing station, hm, as
**      follows:
**
**            p = 1013.25 * exp ( -hm / ( 29.3 * tsl ) );
**
**      Note, however, that the refraction is nearly proportional to
**      the pressure and that an accurate p value is important for
**      precise work.
**
**  Called:  slaI2opa, slaI2oqk
**
**  Last revision:   8 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaI2opa ( double utc, double dut, double elong, double phi,
                double hm, double xp, double yp, double tk, double pmb,
                double rh, double wl, double tlr, IOpars *ioprms )
/*
**  - - - - - - - - -
**   s l a I 2 o p a
**  - - - - - - - - -
**
**  Precompute CIRS to observed place parameters required by slaI2oqk
**  and slaO2iqk.
**
**  Given:
**     utc    double    UTC date/time (MJD, JD-2400000.5)
**     dut    double    delta UT:  UT1-UTC (UTC seconds)
**     elong  double    longitude of the observer (radians, east +ve)
**     phi    double    geodetic latitude of the observer (radians)
**     hm     double    observer's height above sea level (meters)
**     xp     double    polar motion x-coordinate (radians)
**     yp     double    polar motion y-coordinate (radians)
**     tk     double    local ambient temperature (K; std=273.15)
**     pmb    double    local atmospheric pressure (mb; std=1013.25)
**     rh     double    local relative humidity (in the range 0-1)
**     wl     double    effective wavelength (micron, e.g. 0.55)
**     tlr    double    tropospheric lapse rate (K/m, e.g. 0.0065)
**
**  Returned:
**     ioprms IOpars*   star-independent CIRS-to-observed parameters:
**      along     double    longitude + s' + dERA(dut) (radians)
**      phi       double    geodetic latitude (radians)
**      hm        double    height above sea level (meters)
**      xpl       double    polar motion xp wrt local meridian (radians)
**      ypl       double    polar motion yp wrt local meridian (radians)
**      sphi      double    sine of geodetic latitude
**      cphi      double    cosine of geodetic latitude
**      diurab    double    magnitude of diurnal aberration vector
**      p         double    pressure (mb,hPa)
**      tk        double    ambient temperature (K)
**      rh        double    relative humidity (0-1)
**      tlr       double    tropospheric lapse rate (K per meter)
**      wl        double    wavelength (micrometers)
**      refa      double    refraction constant A (radians)
**      refb      double    refraction constant B (radians)
**      eral      double    "local" Earth Rotation Angle (radians)
**
**  Notes:
**
**   1) It is advisable to take great care with units, as even unlikely
**      values of the input parameters are accepted and processed in
**      accordance with the models used.
**
**   2) The utc argument is UTC expressed as an MJD.  This is,
**      strictly speaking, improper, because of leap seconds.  However,
**      as long as the delta UT and the UTC are consistent there are no
**      difficulties, except during a leap second.  In this case, the
**      start of the 61st second of the final minute should begin a new
**      MJD day and the old pre-leap delta UT should continue to be
**      used.  As the 61st second completes, the MJD should revert to
**      the start of the day as, simultaneously, the delta UTC changes
**      by one second to its post-leap new value.
**
**   3) The delta UT (UT1-UTC) is tabulated in IERS bulletins.  It
**      increases by exactly one second at the end of each UTC leap
**      second, introduced in order to keep delta UT within +/- 0.9s.
**
**   4) IMPORTANT -- TAKE CARE WITH THE LONGITUDE SIGN CONVENTION.
**      The longitude required by the present function is east-positive,
**      in accordance with geographical convention (and right-handed).
**      In particular, note that the longitudes returned by the
**      slaObs function are west-positive, following astronomical
**      usage, and must be reversed in sign before use in the present
**      function.
**
**   5) The polar motion coordinates xp,yp can be obtained from IERS
**      bulletins.  The maximum amplitude is about 0.3 arcseconds.  If
**      xp,yp values are unavailable, use zeroes.  The xp,yp
**      coordinates are reckoned as follows:
**
**      . +ve xp means that the point on the geoid directly beneath
**        the CIP is in the hemisphere centered on longitude 90 deg.
**
**      . +ve yp means that the point on the geoid directly beneath
**        the CIP is in the hemisphere centered on longitude 270 deg.
**
**      Internally, the polar motion is stored in a form rotated onto
**      the local meridian.
**
**   6) The height above sea level of the observing station, hm, can be
**      obtained from the Astronomical Almanac (Section J in the 1988
**      edition), or via the function slaObs.  If p, the pressure in
**      millibars, is available, an adequate estimate of hm can be
**      obtained from the expression
**
**            hm = -29.3 * tsl * log ( p / 1013.25 );
**
**      where tsl is the approximate sea-level air temperature in K
**      (See Astrophysical Quantities, C.W.Allen, 3rd edition, section
**      52).  Similarly, if the pressure p is not known, it can be
**      estimated from the height of the observing station, hm, as
**      follows:
**
**            p = 1013.25 * exp ( -hm / ( 29.3 * tsl ) );
**
**      Note, however, that the refraction is nearly proportional to
**      the pressure and that an accurate p value is important for
**      precise work.
**
**   7) The "adjusted longitude" ioprms->along is the observer's
**      longitude plus the tiny quantity s' plus the small amount of ERA
**      that corresponds to the current UT1-UTC.
**
**   8) The "local Earth rotation angle" ioprms->eral is ERA plus the
**      adjusted longitude.
**
**   9) Repeated, computationally-expensive, calls to slaI2opa for
**      times that are very close together can be avoided by calling
**      slaI2opa just once and then using slaI2opat for the subsequent
**      times.  Fresh calls to slaI2opa will be needed only when changes
**      in the polar motion have grown to unacceptable levels or when
**      anything affecting the refraction has changed.
**
**  Defined in slamac.h:  D2PI, DS2R
**
**  Called:  slaSp, slaGeoc, slaRefco, slaI2opat
**
**  Last revision:   9 June 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaI2opad ( IOpars *ioprms )
/*
**  - - - - - - - - - -
**   s l a I 2 o p a d
**  - - - - - - - - - -
**
**  In the CIRS to observed place star-independent parameter structure,
**  disable the diurnal aberration.
**
**  Returned:
**
**     ioprms IOpars*   star-independent CIRS-to-observed parameters:
**      along     double
**      phi       double
**      hm        double
**      xpl       double
**      ypl       double
**      sphi      double
**      cphi      double
**      diurab    double    set to zero
**      p         double
**      tk        double
**      rh        double
**      tlr       double
**      wl        double
**      refa      double
**      refb      double
**      eral      double
**
**  Notes:
**
**  1  This capability is provided to bypass the geocentric stage in the
**     transformation from ICRS to CIRS coordinates;  the site velocity
**     and position can be specified at that point.  One motivation for
**     doing so would be to include (stellar) geocentric parallax, which
**     is neglected in the slaI2o functions.
**
**  2  To re-instate the correction for diurnal aberration, use
**     slaI2opa.
**
**  3  For more information, see slaI2opa.
**
**  Last revision:   17 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaI2opat ( double utc, IOpars *ioprms )
/*
**  - - - - - - - - - -
**   s l a I 2 o p a t
**  - - - - - - - - - -
**
**  Recompute the Earth rotation angle in the CIRS to observed place
**  star-independent parameter structure.
**
**  Given:
**
**     utc    double  UTC date/time (modified Julian Date, JD-2400000.5)
**                    (see slaI2opa for comments on leap seconds)
**
**     ioprms IOpars* star-independent CIRS-to-observed parameters:
**      along     double    longitude + s' + dERA(dut) (radians)
**      phi       double    geodetic latitude (radians)
**      hm        double    height above sea level (meters)
**      xpl       double    polar motion xp wrt local meridian (radians)
**      ypl       double    polar motion yp wrt local meridian (radians)
**      sphi      double    sine of geodetic latitude
**      cphi      double    cosine of geodetic latitude
**      diurab    double    magnitude of diurnal aberration vector
**      p         double    pressure (mb,hPa)
**      tk        double    ambient temperature (K)
**      rh        double    relative humidity (0-1)
**      tlr       double    tropospheric lapse rate (K per meter)
**      wl        double    wavelength (micrometers)
**      refa      double    refraction constant A (radians)
**      refb      double    refraction constant B (radians)
**      eral      double    "local" Earth Rotation Angle (radians)
**
**  Returned:
**
**     ioprms IOpars*   star-independent CIRS-to-observed parameters:
**      along     double    unchanged
**      phi       double    unchanged
**      hm        double    unchanged
**      xpl       double    unchanged
**      ypl       double    unchanged
**      sphi      double    unchanged
**      cphi      double    unchanged
**      diurab    double    unchanged
**      p         double    unchanged
**      tk        double    unchanged
**      rh        double    unchanged
**      tlr       double    unchanged
**      wl        double    unchanged
**      refa      double    unchanged
**      refb      double    unchanged
**      eral      double    "local" Earth rotation angle (radians)
**
**  Notes:
**
**  1  The utc argument is UTC expressed as an MJD.  This is,
**     strictly speaking, improper, because of leap seconds.  However,
**     as long as the delta UT and the UTC are consistent there are no
**     difficulties, except during a leap second.  In this case, the
**     start of the 61st second of the final minute should begin a new
**     MJD day and the old pre-leap delta UT should continue to be
**     used.  As the 61st second completes, the MJD should revert to
**     the start of the day as, simultaneously, the delta UTC changes
**     by one second to its post-leap new value.
**
**  2  The delta UT (UT1-UTC) is tabulated in IERS bulletins.  It
**     increases by exactly one second at the end of each UTC leap
**     second, introduced in order to keep delta UT within +/- 0.9s.
**
**  3  The "adjusted longitude" ioprms->along is the observer's
**     longitude plus the tiny quantity s' plus the small amount of ERA
**     that corresponds to the current UT1-UTC.
**
**  4  The "local Earth rotation angle" ioprms->eral is ERA plus the
**     adjusted longitude.
**
**  Called:  slaEra
**
**  Last revision:   20 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaI2oqk ( double ri, double di, IOpars *ioprms,
                double *aob, double *zob,
                double *hob, double *dob, double *rob )
/*
**  - - - - - - - - -
**   s l a I 2 o q k
**  - - - - - - - - -
**
**  Quick CIRS to observed place (but see Note 8, below, for remarks
**  about speed).
**
**  Given:
**     ri     double    CIRS right ascension
**     di     double    CIRS declination
**     ioprms IOpars*   star-independent CIRS-to-observed parameters:
**      along     double    longitude + s' + dERA(dut) (radians)
**      phi       double    geodetic latitude (radians)
**      hm        double    height above sea level (meters)
**      xpl       double    polar motion xp wrt local meridian (radians)
**      ypl       double    polar motion yp wrt local meridian (radians)
**      sphi      double    sine and cosine of geodetic latitude
**      cphi      double    sine and cosine of geodetic latitude
**      diurab    double    magnitude of diurnal aberration vector
**      p         double    pressure (mb,hPa)
**      tk        double    ambient temperature (K)
**      rh        double    relative humidity (0-1)
**      tlr       double    tropospheric lapse rate (K per meter)
**      wl        double    wavelength (micrometers)
**      refa      double    refraction constant A (radians)
**      refb      double    refraction constant B (radians)
**      eral      double    "local" Earth Rotation Angle (radians)
**
**  Returned:
**     aob    double    observed azimuth (radians: N=0,E=90)
**     zob    double    observed zenith distance (radians)
**     hob    double    observed hour angle (radians)
**     dob    double    observed declination (radians)
**     rob    double    observed right ascension (CEO-based, radians)
**
**  Notes:
**
**   1)  This function returns zenith distance rather than elevation
**       in order to reflect the fact that no allowance is made for
**       depression of the horizon.
**
**   2)  The accuracy of the result is limited by the corrections for
**       refraction.  Providing the meteorological parameters are
**       known accurately and there are no gross local effects, the
**       observed RA,Dec predicted by this function should be within
**       about 0.1 arcsec for a zenith distance of less than 70 degrees.
**       Even at a topocentric zenith distance of 90 degrees, the
**       accuracy in elevation should be better than 1 arcmin;  useful
**       results are available for a further 3 degrees, beyond which
**       the slaRefro function returns a fixed value of the refraction.
**       The complementary functions slaI2o (or slaI2oqk) and slaO2i
**       (or slaO2iqk) are self-consistent to better than 1 micro-
**       arcsecond all over the celestial sphere.
**
**   3)  It is advisable to take great care with units, as even
**       unlikely values of the input parameters are accepted and
**       processed in accordance with the models used.
**
**   4)  The CIRS RA,Dec is obtained from a star catalogue mean place by
**       allowing for space motion, parallax, the Sun's gravitational
**       lens effect, annual aberration and precession-nutation.  For
**       star positions in the ICRS, these effects can be applied by
**       means of the slaC2i (etc.) functions.  Starting from the
**       formerly used "mean place" systems, additional transformations
**       will be needed first.
**
**   5)  "Observed" Az,El means the position that would be seen by a
**       perfect theodolite located at the observer.  This is obtained
**       from the CIRS RA,Dec by allowing for Earth orientation and
**       diurnal aberration, rotating from equator to horizon
**       coordinates, and then adjusting for refraction.  The HA,Dec is
**       obtained by rotating back into equatorial coordinates, and is
**       the position that would be seen by a perfect equatorial located
**       at the observer and with its polar axis aligned to the Earth's
**       axis of rotation (n.b. not to the refracted pole).  Finally,
**       the RA is obtained by subtracting the HA from the local ERA.
**
**   6)  To predict the required setting of a real telescope, the
**       observed place produced by this function would have to be
**       adjusted for the tilt of the azimuth or polar axis of the
**       mounting (with appropriate corrections for mount flexures),
**       for the non-perpendicularities between the two mount axes and
**       between the reference pointing axis and the mount declination
**       or elevation axis, for the desired image location in the focal
**       plane, for tube flexure, for gear and encoder errors, and
**       finally for encoder zero points.  Some telescopes would, of
**       course, exhibit other properties which would need to be
**       accounted for at the appropriate point in the sequence.
**
**   7)  The star-independent CIRS-to-observed-place parameters in
**       ioprms may be computed by means of the slaI2opa function.  If
**       nothing has changed significantly except the time, the
**       slaI2opat function may be used to perform the requisite partial
**       recomputation of ioprms.
**
**   8)  At zenith distances beyond about 76 degrees, the need for
**       special care with the corrections for refraction causes a
**       marked increase in execution time.  Moreover, the effect
**       gets worse with increasing zenith distance.  Adroit
**       programming in the calling application may allow the
**       problem to be reduced.  Prepare an alternative ioprms
**       structure, computed for zero air-pressure;  this will disable
**       the refraction corrections and cause rapid execution.  Using
**       this ioprms structure, a preliminary call to the present
**       function will, depending on the application, produce a rough
**       position which may be enough to establish whether the full,
**       slow calculation (using the real ioprms structure) is
**       worthwhile.  For example, there would be no need for the full
**       calculation if the preliminary call had already established
**       that the source was well below the elevation limits for a
**       particular telescope or antenna.
**
**  Called:  slaDcs2c,  slaRefz,  slaRefro,  slaDcc2s,  slaDranrm
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaImxv ( float rm[3][3], float va[3], float vb[3] )
/*
**  - - - - - - - -
**   s l a I m x v
**  - - - - - - - -
**
**  Performs the 3-d backward unitary transformation:
**
**     vector vb = (inverse of matrix rm) * vector va
**
**  (single precision)
**
**  n.b.  The matrix must be unitary, as this function assumes that
**        the inverse and transpose are identical.
**
**  Given:
**     rm       float[3][3]    matrix
**     va       float[3]       vector
**
**  Returned:
**     vb       float[3]       result vector
**
**  The same vector can be specified for both va and vb.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaInt2in ( char *string, int *nstrt, int *ireslt, int *jflag )
/*
**  - - - - - - - - - -
**   s l a I n t 2 i n
**  - - - - - - - - - -
**
**  Convert free-format input into an integer.
**
**  Given:
**     string    char*    string containing number to be decoded
**     nstrt     int*     where to start decode (1st = 1)
**     ireslt    long*    current value of result
**
**  Returned:
**     nstrt     int*     advanced to next number
**     ireslt    int*     result
**     jflag     int*     status: -1 = -OK, 0 = +OK, 1 = null, 2 = error
**
**  Notes:
**
**     1     The reason slaInt2in has separate OK status values for +
**           and - is to enable minus zero to be detected.   This is
**           of crucial importance when decoding mixed-radix numbers.
**           For example, an angle expressed as deg, arcmin, arcsec
**           may have a leading minus sign but a zero degrees field.
**
**     2     A TAB is interpreted as a space.
**
**     3     The basic format is the sequence of fields #^, where
**           # is a sign character + or -, and ^ means a string of
**           decimal digits.
**
**     4     Spaces:
**
**             .  Leading spaces are ignored.
**
**             .  Spaces between the sign and the number are allowed.
**
**             .  Trailing spaces are ignored;  the first signifies
**                end of decoding and subsequent ones are skipped.
**
**     5     Delimiters:
**
**             .  Any character other than +,-,0-9 or space may be
**                used to signal the end of the number and terminate
**                decoding.
**
**             .  Comma is recognized by slaInt2in as a special case;
**                it is skipped, leaving the pointer on the next
**                character.  See 9, below.
**
**     6     The sign is optional.  The default is +.
**
**     7     A "null result" occurs when the string of characters being
**           decoded does not begin with +,- or 0-9, or consists
**           entirely of spaces.  When this condition is detected, jflag
**           is set to 1 and ireslt is left untouched.
**
**     8     nstrt = 1 for the first character in the string.
**
**     9     On return from slaInt2in, nstrt is set ready for the next
**           decode - following trailing blanks and any comma.  If a
**           delimiter other than comma is being used, nstrt must be
**           incremented before the next call to slaInt2in, otherwise
**           all subsequent calls will return a null result.
**
**     10    Errors (jflag=2) occur when:
**
**             .  there is a + or - but no number;  or
**
**             .  the number is larger than INT_MAX.
**
**     11    When an error has been detected, nstrt is left
**           pointing to the character following the last
**           one used before the error came to light.
**
**     12    See also slaIntin, slaFlotin and slaDfltin.
**
**  Last revision:   10 December 2002
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaIntin ( char *string, int *nstrt, long *ireslt, int *jflag )
/*
**  - - - - - - - - -
**   s l a I n t i n
**  - - - - - - - - -
**
**  Convert free-format input into a long integer.
**
**  Given:
**     string    char*    string containing number to be decoded
**     nstrt     int*     where to start decode (1st = 1)
**     ireslt    long*    current value of result
**
**  Returned:
**     nstrt     int*     advanced to next number
**     ireslt    long*    result
**     jflag     int*     status: -1 = -OK, 0 = +OK, 1 = null, 2 = error
**
**  Called:  idchi
**
**  Notes:
**
**     1     The reason slaIntin has separate OK status values for +
**           and - is to enable minus zero to be detected.   This is
**           of crucial importance when decoding mixed-radix numbers.
**           For example, an angle expressed as deg, arcmin, arcsec
**           may have a leading minus sign but a zero degrees field.
**
**     2     A TAB is interpreted as a space.
**
**     3     The basic format is the sequence of fields #^, where
**           # is a sign character + or -, and ^ means a string of
**           decimal digits.
**
**     4     Spaces:
**
**             .  Leading spaces are ignored.
**
**             .  Spaces between the sign and the number are allowed.
**
**             .  Trailing spaces are ignored;  the first signifies
**                end of decoding and subsequent ones are skipped.
**
**     5     Delimiters:
**
**             .  Any character other than +,-,0-9 or space may be
**                used to signal the end of the number and terminate
**                decoding.
**
**             .  Comma is recognized by slaIntin as a special case;  it
**                is skipped, leaving the pointer on the next character.
**                See 9, below.
**
**     6     The sign is optional.  The default is +.
**
**     7     A "null result" occurs when the string of characters being
**           decoded does not begin with +,- or 0-9, or consists
**           entirely of spaces.  When this condition is detected, jflag
**           is set to 1 and ireslt is left untouched.
**
**     8     nstrt = 1 for the first character in the string.
**
**     9     On return from slaIntin, nstrt is set ready for the next
**           decode - following trailing blanks and any comma.  If a
**           delimiter other than comma is being used, nstrt must be
**           incremented before the next call to slaIntin, otherwise
**           all subsequent calls will return a null result.
**
**     10    Errors (jflag=2) occur when:
**
**             .  there is a + or - but no number;  or
**
**             .  the number is larger than LONG_MAX.
**
**     11    When an error has been detected, nstrt is left
**           pointing to the character following the last
**           one used before the error came to light.
**
**     12    See also slaInt2in, slaFlotin and slaDfltin.
**
**  Last revision:   2 January 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaInvf ( double fwds[6], double bkwds[6], int *j )
/*
**  - - - - - - - -
**   s l a I n v f
**  - - - - - - - -
**
**  Invert a linear model of the type produced by the slaFitxy function.
**
**  Given:
**     fwds    double[6]      model coefficients
**
**  Returned:
**     bkwds   double[6]      inverse model
**     *j      int            status:  0 = OK, -1 = no inverse
**
**  The models relate two sets of [x,y] coordinates as follows.
**  Naming the elements of fwds:
**
**     fwds[0] = a
**     fwds[1] = b
**     fwds[2] = c
**     fwds[3] = d
**     fwds[4] = e
**     fwds[5] = f
**
**  Where two sets of coordinates [x1,y1] and [x2,y1] are related
**  thus:
**
**     x2 = a + b*x1 + c*y1
**     y2 = d + e*x1 + f*y1
**
**  The present function generates a new set of coefficients:
**
**     bkwds[0] = p
**     bkwds[1] = q
**     bkwds[2] = r
**     bkwds[3] = s
**     bkwds[4] = t
**     bkwds[5] = u
**
**  Such that:
**
**     x1 = p + q*x2 + r*y2
**     y1 = s + t*x2 + u*y2
**
**  Two successive calls to slaInvf will thus deliver a set
**  of coefficients equal to the starting values.
**
**  See also slaFitxy, slaPxy, slaXy2xy, slaDcmpf
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaKbj ( int jb, double e, char *k, int *j )
/*
**  - - - - - - -
**   s l a K b j
**  - - - - - - -
**
**  Select epoch prefix 'B' or 'J'.
**
**  Given:
**     jb     int         slaDbjin prefix status:  0=none, 1='B', 2='J'
**     e      double      epoch - Besselian or Julian
**
**  Returned:
**     *k     char        'B' or 'J'
**     *j     int         status:  0=OK
**
**  If jb=0, B is assumed for e < 1984.0, otherwise J.
**
**  Last revision:   23 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaM2av ( float rmat[3][3], float axvec[3] )
/*
**  - - - - - - - -
**   s l a M 2 a v
**  - - - - - - - -
**
**  From a rotation matrix, determine the corresponding axial vector.
**
**  (single precision)
**
**  A rotation matrix describes a rotation about some arbitrary axis,
**  called the Euler axis.  The "axial vector" returned by this function
**  has the same direction as the Euler axis, and its magnitude is the
**  amount of rotation in radians.  (The magnitude and direction can be
**  separated by means of the function slaVn.)
**
**  Given:
**    rmat   float[3][3]   rotation matrix
**
**  Returned:
**    axvec  float[3]      axial vector (radians)
**
**  The reference frame rotates clockwise as seen looking along
**  the axial vector from the origin.
**
**  If rmat is null, so is the result.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaMap ( double rm, double dm, double pr, double pd,
              double px, double rv, double eq, double date,
              double *ra, double *da )
/*
**  - - - - - - -
**   s l a M a p
**  - - - - - - -
**
**  Transform star RA,Dec from mean place to geocentric apparent.
**
**  The reference frames and timescales used are post IAU 1976.
**
**  References:
**     1984 Astronomical Almanac, pp B39-B41.
**     (also Lederle & Schwan, Astron. Astrophys. 134, 1-6, 1984)
**
**  Given:
**     rm,dm    double     mean RA,Dec (rad)
**     pr,pd    double     proper motions:  RA,Dec changes per Julian year
**     px       double     parallax (arcsec)
**     rv       double     radial velocity (km/sec, +ve if receding)
**     eq       double     epoch and equinox of star data (Julian)
**     date     double     TDB for apparent place (JD-2400000.5)
**
**  Returned:
**     *ra,*da  double     apparent RA,Dec (rad)
**
**  Called:
**     slaMappa       star-independent parameters
**     slaMapqk       quick mean to apparent
**
**  Notes:
**
**  1)  eq is the Julian epoch specifying both the reference frame and
**      the epoch of the position - usually 2000.  For positions where
**      the epoch and equinox are different, use the function slaPm to
**      apply proper motion corrections before using this function.
**
**  2)  The distinction between the required TDB and TT is always
**      negligible.  Moreover, for all but the most critical
**      applications UTC is adequate.
**
**  3)  The proper motions in RA are dRA/dt rather than cos(Dec)*dRA/dt.
**
**  4)  This function may be wasteful for some applications because it
**      recomputes the Earth position/velocity and the precession-
**      nutation matrix each time, and because it allows for parallax
**      and proper motion.  Where multiple transformations are to be
**      carried out for one epoch, a faster method is to call the
**      slaMappa function once and then either the slaMapqk function
**      (which includes parallax and proper motion) or slaMapqkz (which
**      assumes zero parallax and proper motion).
**
**  5)  The accuracy is sub-milliarcsecond, limited by the
**      precession-nutation model (IAU 1976 precession, Shirai &
**      Fukushima 2001 forced nutation and precession corrections).
**
**  6)  The accuracy is further limited by the function slaEvp, called
**      by slaMappa, which computes the Earth position and velocity
**      using the methods of Stumpff.  The maximum error is about
**      0.3 mas.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaMappa ( double eq, double date, double amprms[21] )
/*
**  - - - - - - - - -
**   s l a M a p p a
**  - - - - - - - - -
**
**  Compute star-independent parameters in preparation for
**  conversions between mean place and geocentric apparent place.
**
**  The parameters produced by this function are required in the
**  parallax, light deflection, aberration, and precession/nutation
**  parts of the mean/apparent transformations.
**
**  The reference frames and timescales used are post IAU 1976.
**
**  Given:
**     eq       double      epoch of mean equinox to be used (Julian)
**     date     double      TDB (JD-2400000.5)
**
**  Returned:
**     amprms   double[21]  star-independent mean-to-apparent parameters:
**
**       (0)      time interval for proper motion (Julian years)
**       (1-3)    barycentric position of the Earth (AU)
**       (4-6)    heliocentric direction of the Earth (unit vector)
**       (7)      (grav rad Sun)*2/(Sun-Earth distance)
**       (8-10)   abv: barycentric Earth velocity in units of c
**       (11)     sqrt(1-v**2) where v=modulus(abv)
**       (12-20)  precession/nutation (3,3) matrix
**
**  References:
**     1984 Astronomical Almanac, pp B39-B41.
**     (also Lederle & Schwan, Astron. Astrophys. 134, 1-6, 1984)
**
**  Notes:
**
**  1)  For date, the distinction between the required TDB and TT
**      is always negligible.  Moreover, for all but the most
**      critical applications UTC is adequate.
**
**  2)  The vectors amprms(1-3) and amprms(4-6) are referred to the
**      mean equinox and equator of epoch eq.
**
**  3)  The parameters AMPRMS produced by this function are used by
**      slaAmpqk, slaMapqk and slaMapqkz.
**
**  4)  The accuracy is sub-milliarcsecond, limited by the
**      precession-nutation model (IAU 1976 precession, Shirai &
**      Fukushima 2001 forced nutation and precession corrections).
**
**  5)  A further limit to the accuracy of functions using the parameter
**      array AMPRMS is imposed by the function slaEvp, used here to
**      compute the Earth position and velocity by the methods of
**      Stumpff.  The maximum error in the resulting aberration
**      corrections is about 0.3 milliarcsecond.
**
**  Called:
**     slaEpj, slaEvp, slaDvn, slaPrenut
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaMapqk ( double rm, double dm, double pr, double pd,
                double px, double rv, double amprms[21],
                double *ra, double *da )
/*
**  - - - - - - - - -
**   s l a M a p q k
**  - - - - - - - - -
**
**  Quick mean to apparent place:  transform a star RA,Dec from
**  mean place to geocentric apparent place, given the
**  star-independent parameters.
**
**  Use of this function is appropriate when efficiency is important
**  and where many star positions, all referred to the same equator
**  and equinox, are to be transformed for one epoch.  The
**  star-independent parameters can be obtained by calling the
**  slaMappa function.
**
**  If the parallax and proper motions are zero the slaMapqkz
**  function can be used instead.
**
**  The reference frames and timescales used are post IAU 1976.
**
**  Given:
**     rm,dm    double      mean RA,Dec (rad)
**     pr,pd    double      proper motions:  RA,Dec changes per Julian year
**     px       double      parallax (arcsec)
**     rv       double      radial velocity (km/sec, +ve if receding)
**
**     amprms   double[21]  star-independent mean-to-apparent parameters:
**
**       (0)      time interval for proper motion (Julian years)
**       (1-3)    barycentric position of the Earth (AU)
**       (4-6)    heliocentric direction of the Earth (unit vector)
**       (7)      (grav rad Sun)*2/(Sun-Earth distance)
**       (8-10)   barycentric Earth velocity in units of c
**       (11)     sqrt(1-v**2) where v=modulus(abv)
**       (12-20)  precession/nutation (3,3) matrix
**
**  Returned:
**     *ra,*da  double      apparent RA,Dec (rad)
**
**  References:
**     1984 Astronomical Almanac, pp B39-B41.
**     (also Lederle & Schwan, Astron. Astrophys. 134, 1-6, 1984)
**
**  Notes:
**
**    1)  The vectors amprms(1-3) and amprms(4-6) are referred to
**        the mean equinox and equator of epoch eq.
**
**    2)  Strictly speaking, the function is not valid for solar-system
**        sources, though the error will usually be extremely small.
**        However, to prevent gross errors in the case where the
**        position of the Sun is specified, the gravitational
**        deflection term is restrained within about 920 arcsec of the
**        centre of the Sun's disc.  The term has a maximum value of
**        about 1.85 arcsec at this radius, and decreases to zero as
**        the centre of the disc is approached.
**
**    3)  See the slaMap function for further information.
**
**  Called:
**     slaDcs2c       spherical to Cartesian
**     slaDvdv        dot product
**     slaDmxv        matrix x vector
**     slaDcc2s       Cartesian to spherical
**     slaDranrm      normalize angle 0-2pi
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaMapqkz ( double rm, double dm, double amprms[21],
                 double *ra, double *da )
/*
**  - - - - - - - - - -
**   s l a M a p q k z
**  - - - - - - - - - -
**
**  Quick mean to apparent place:  transform a star RA,dec from
**  mean place to geocentric apparent place, given the
**  star-independent parameters, and assuming zero parallax
**  and proper motion.
**
**  Use of this function is appropriate when efficiency is important
**  and where many star positions, all with parallax and proper
**  motion either zero or already allowed for, and all referred to
**  the same equator and equinox, are to be transformed for one
**  epoch.  The star-independent parameters can be obtained by
**  calling the slaMappa function.
**
**  The corresponding function for the case of non-zero parallax
**  and proper motion is slaMapqk.
**
**  The reference frames and timescales used are post IAU 1976.
**
**  Given:
**     rm,dm    double     mean RA,dec (rad)
**     amprms   double[21] star-independent mean-to-apparent parameters:
**
**       (0-3)    not used
**       (4-6)    heliocentric direction of the Earth (unit vector)
**       (7)      (grav rad Sun)*2/(Sun-Earth distance)
**       (8-10)   abv: barycentric Earth velocity in units of c
**       (11)     sqrt(1-v**2) where v=modulus(abv)
**       (12-20)  precession/nutation (3,3) matrix
**
**  Returned:
**     *ra,*da  double     apparent RA,dec (rad)
**
**  References:
**     1984 Astronomical Almanac, pp B39-B41.
**     (also Lederle & Schwan, Astron. Astrophys. 134,
**      1-6, 1984)
**
**  Notes:
**
**    1)  The vectors amprms(1-3) and amprms(4-6) are referred to the
**        mean equinox and equator of epoch eq.
**
**    2)  Strictly speaking, the function is not valid for solar-system
**        sources, though the error will usually be extremely small.
**        However, to prevent gross errors in the case where the
**        position of the Sun is specified, the gravitational
**        deflection term is restrained within about 920 arcsec of the
**        centre of the Sun's disc.  The term has a maximum value of
**        about 1.85 arcsec at this radius, and decreases to zero as
**        the centre of the disc is approached.
**
**  Called:
**     slaDcs2c       spherical to Cartesian
**     slaDvdv        dot product
**     slaDmxv        matrix x vector
**     slaDcc2s       Cartesian to spherical
**     slaDranrm      normalize angle 0-2pi
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaMoon ( int iy, int id, float fd, float pv[6] )
/*
**  - - - - - - - -
**   s l a M o o n
**  - - - - - - - -
**
**  Approximate geocentric position and velocity of the Moon
**  (single precision).
**
**  Given:
**     iy       int        year
**     id       int        day in year (1 = Jan 1st)
**     fd       float      fraction of day
**
**  Returned:
**     pv       float[6]   Moon position & velocity vector
**
**  Notes:
**
**  1  The date and time is TDB (loosely ET) in a Julian calendar
**     which has been aligned to the ordinary Gregorian
**     calendar for the interval 1900 March 1 to 2100 February 28.
**     The year and day can be obtained by calling slaCalyd or
**     slaClyd.
**
**  2  The Moon 6-vector is Moon centre relative to Earth centre,
**     mean equator and equinox of date.  Position part, pv[0-2],
**     is in AU;  velocity part, pv[3-5], is in AU/sec.
**
**  3  The position is accurate to better than 0.5 arcminute
**     in direction and 1000 km in distance.  The velocity
**     is accurate to better than 0.5"/hour in direction and
**     4 m/s in distance.  (RMS figures with respect to JPL DE200
**     for the interval 1960-2025 are 14 arcsec and 0.2 arcsec/hour in
**     longitude, 9 arcsec and 0.2 arcsec/hour in latitude, 350 km and
**     2 m/s in distance.)  Note that the distance accuracy is
**     comparatively poor because this function is principally intended
**     for computing topocentric direction.
**
**  4  This function is only a partial implementation of the original
**     Meeus algorithm (reference below), which offers 4 times the
**     accuracy in direction and 30 times the accuracy in distance
**     when fully implemented (as it is in slaDmoon).
**
**  Reference:
**     Meeus, l'Astronomie, June 1984, p348.
**
**  Defined in slamac.h:  dmod
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaMxm ( float a[3][3], float b[3][3], float c[3][3] )
/*
**  - - - - - - -
**   s l a M x m
**  - - - - - - -
**
**  Product of two 3x3 matrices:
**
**     matrix c  =  matrix a  x  matrix b
**
**  (single precision)
**
**  Given:
**     a      float[3][3]        matrix
**     b      float[3][3]        matrix
**
**  Returned:
**     c      float[3][3]        matrix result
**
**  Note:  the same array may be nominated more than once.
**
**  Last revision:   6 November 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaMxv ( float rm[3][3], float va[3], float vb[3] )
/*
**  - - - - - - -
**   s l a M x v
**  - - - - - - -
**
**  Perform the 3-d forward unitary transformation:
**
**     vector vb = matrix rm * vector va
**
**  (single precision)
**
**  Given:
**     rm       float[3][3]   matrix
**     va       float[3]      vector
**
**  Returned:
**     vb       float[3]      result vector
**
**  Note:  va and vb may be the same array.
**
**  Last revision:   6 November 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaNu ( double date, double *dpsi, double *deps )
/*
**  - - - - - -
**   s l a N u
**  - - - - - -
**
**  Nutation, IAU 2006 model (IAU 2000A nutation with corrections
**  applied to match the IAU 2006 precession).
**
**  Given:
**     date        double   TDB Modified Julian Date
**
**  Returned:
**     dpsi,deps   double*  nutation, luni-solar + planetary
**
**  Called:  slaNu00a
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT will do.
**
**  2) The nutation components in longitude and obliquity are with
**     respect to the mean equinox and ecliptic of date, IAU 2006
**     precession model (Hilton et al. 2006, Capitaine et al. 2005).
**
**  3) The function first computes the IAU 2000A nutation then applies
**     corrections for (i) the consequences of the change in obliquity
**     from the IAU 1980 ecliptic to the IAU 2006 ecliptic and (ii) the
**     secular variation in the Earth's dynamical flattening, not taken
**     into account in the IAU 2000A model.
**
**  4) The present function provides classical nutation, supplementing
**     the IAU 2000 frame bias and IAU 2006 precession.  It delivers a
**     pole which is at current epochs accurate to a few tens of
**     microarcseconds, apart from the omission of the free core
**     nutation.
**
**  References:
**
**     Capitaine, N., Wallace, P.T. & Chapront, J. 2005,
**     Astron.Astrophys. 432, 355-357
**
**     Hilton, J. et al., 2006, Celest.Mech.Dyn.Astron. 94, 351
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaNu00a ( double date, double *dpsi, double *deps )
/*
**  - - - - - - - - -
**   s l a N u 0 0 a
**  - - - - - - - - -
**
**  Nutation, IAU 2000A model (MHB_2000 luni-solar and planetary nutation
**  with free core nutation omitted).
**
**  Given:
**     date        double    TDB Modified Julian Date (Note 1)
**
**  Returned:
**     dpsi,deps   double*   nutation, luni-solar + planetary (Note 2)
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT will do.
**
**  2) The nutation components in longitude and obliquity are with
**     respect to the equinox and ecliptic of date.  The obliquity at
**     J2000 is assumed to be the Lieske et al. (1977) value of
**     84381.448 arcsec.
**
**  3) Both the luni-solar and planetary nutations are included.  The
**     latter are due to direct planetary nutations and the
**     perturbations of the lunar and terrestrial orbits.
**
**  4) The function computes the MHB_2000 nutation series with the
**     associated corrections for planetary nutations.  It is an
**     implementation of the nutation part of the IAU 2000A precession-
**     nutation model, formally adopted by the IAU General Assembly in
**     2000, namely MHB2000 (Mathews et al. 2002), but with the free
**     core nutation (FCN - see Note 5) omitted.
**
**  5) The full MHB_2000 model also contains contributions to the
**     nutations in longitude and obliquity due to the free-excitation
**     of the free-core-nutation during the period 1979-2000.  These FCN
**     terms, which are time-dependent and unpredictable, are NOT
**     included in the present function and, if required, must be
**     independently computed.  With the FCN corrections included, the
**     present function delivers a pole which is at current epochs
**     accurate to a few hundred microarcseconds.  The omission of FCN
**     introduces further errors of about that size.
**
**  6) The present function provides classical nutation.  The MHB_2000
**     algorithm, from which it is adapted, deals also with (i) the
**     offsets between the ICRS and mean poles and (ii) the adjustments
**     in longitude and obliquity due to the changed precession rates
**     with respect to IAU 1976 precession.
**
**  References:
**
**     Chapront, J., Chapront-Touze, M. & Francou, G. 2002,
**     Astron.Astrophys. 387, 700
**
**     Lieske, J.H., Lederle, T., Fricke, W. & Morando, B. 1977,
**     Astron.Astrophys. 58, 1-16
**
**     Mathews, P.M., Herring, T.A., Buffet, B.A. 2002, J.Geophys.Res.
**     107, B4.  The MHB_2000 code itself was obtained on 9th September
**     2002 from ftp//maia.usno.navy.mil/conv2000/chapter5/IAU2000A.
**
**     Simon, J.-L., Bretagnon, P., Chapront, J., Chapront-Touze, M.,
**     Francou, G., Laskar, J. 1994, Astron.Astrophys. 282, 663-683
**
**     Souchay, J., Loysel, B., Kinoshita, H., Folgueira, M. 1999,
**     Astron.Astrophys.Supp.Ser. 135, 111
**
**  Defined in slamac.h:  DAS2R, D2PI
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
**
*/


void slaNut ( double date, double rmatn[3][3] )
/*
**  - - - - - - -
**   s l a N u t
**  - - - - - - -
**
**  Form the matrix of nutation for a given date - Shirai & Fukushima
**  2001 theory
**
**  (double precision)
**
**  Reference:
**     Shirai, T. & Fukushima, T., Astron.J. 121, 3270-3283 (2001).
**
**  Given:
**     date   double        TDB (loosely ET) as Modified Julian Date
**                                           (=JD-2400000.5)
**
**  Returned:
**     rmatn  double[3][3]  nutation matrix
**
**  Notes:
**
**  1  The matrix is in the sense  v(true) = rmatn * v(mean) .
**     where v(true) is the star vector relative to the true equator and
**     equinox of date and v(mean) is the star vector relative to the
**     mean equator and equinox of date.
**
**  2  The matrix represents forced nutation (but not free core
**     nutation) plus corrections to the IAU~1976 precession model.
**
**  3  Earth attitude predictions made by combining the present nutation
**     matrix with IAU~1976 precession are accurate to 1~mas (with
**     respect to the ICRS) for a few decades around 2000.
**
**  4  The distinction between the required TDB and TT is always
**     negligible.  Moreover, for all but the most critical applications
**     UTC is adequate.
**
**  Called:   slaNutc, slaDeuler
**
**  Last revision:   1 December 2005
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaNutc ( double date, double *dpsi, double *deps, double *eps0 )
/*
**  - - - - - - - -
**   s l a N u t c
**  - - - - - - - -
**
**  Nutation:  longitude & obliquity components and mean obliquity,
**  using the Shirai & Fukushima (2001) theory.
**
**  Given:
**     date        double    TDB (loosely ET) as Modified Julian Date
**                                                 (JD-2400000.5)
**  Returned:
**     dpsi,deps   double    nutation in longitude,obliquity
**     eps0        double    mean obliquity
**
**  Notes:
**
**  1  The function predicts forced nutation (but not free core
**     nutation) plus corrections to the IAU 1976 precession model.
**
**  2  Earth attitude predictions made by combining the present nutation
**     model with IAU 1976 precession are accurate to 1 mas (with
**     respect to the ICRS) for a few decades around 2000.
**
**  3  The slaNutc80 function is the equivalent of the present function
**     but using the IAU 1980 nutation theory.  The older theory is less
**     accurate, leading to errors as large as 350 mas over the interval
**     1900-2100, mainly because of the error in the IAU 1976
**     precession.
**
**  References:
**
**     Shirai, T. & Fukushima, T., 2001, Astron.J. 121, 3270-3283
**
**     Fukushima, T., 1991, Astron.Astrophys. 244, L11
**
**     Simon, J. L., Bretagnon, P., Chapront, J., Chapront-Touze, M.,
**     Francou, G. & Laskar, J., 1994, Astron.Astrophys. 282, 663
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaNutc80 ( double date, double *dpsi, double *deps, double *eps0 )
/*
**  - - - - - - - - - -
**   s l a N u t c 8 0
**  - - - - - - - - - -
**
**  Nutation:  longitude & obliquity components and mean obliquity,
**  using the IAU 1980 theory
**
**  (double precision)
**
**  Given:
**     date        double    TDB (loosely ET) as Modified Julian Date
**                                            (JD-2400000.5)
**  Returned:
**     dpsi,deps   double*   nutation in longitude,obliquity
**     eps0        double*   mean obliquity
**
**  Notes:
**
**  1  Earth attitude predictions made by combining the present nutation
**     model with IAU 1976 precession are accurate to 0.35 arcsec over
**     the interval 1900-2100.  (The accuracy is much better near the
**     middle of the interval.)
**
**  2  The slaNutc function is the equivalent of the present function
**     but using the Shirai & Fukushima 2001 forced nutation theory
**     (SF2001).  The newer theory is more accurate than IAU 1980,
**     within 1 mas (with respect to the ICRF) for a few decades around
**     2000.  The improvement is mainly because of the corrections to
**     the IAU 1976 precession that the SF2001 theory includes.
**
**  References:
**     Final report of the IAU working group on nutation,
**      chairman P.K.Seidelmann, 1980.
**     Kaplan,G.H., 1981, USNO circular No. 163, pa3-6.
**
**  Called:  slaDrange
**
**  Defined in slamac.h:  DAS2R, dmod
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaO2i ( char *type, double ob1, double ob2, double date,
              double dut, double elong, double phi, double hm,
              double xp, double yp, double tk, double pmb, double rh,
              double wl, double tlr, double *ri, double *di )
/*
**  - - - - - - -
**   s l a O 2 i
**  - - - - - - -
**
**  Observed place to CIRS:  observed place at a ground based site to
**  CIRS RA,Dec, for sources distant from the solar system.
**
**  Given:
**     type  char[]   type of coordinates - "R", "H" or "A" (see below)
**     ob1   double   observed Az, HA or RA (radians; Az is N=0,E=90)
**     ob2   double   observed ZD or Dec (radians)
**     date  double   UTC date/time (modified Julian Date, JD-2400000.5)
**     dut   double   delta UT:  UT1-UTC (UTC seconds)
**     elong double   longitude of the observer (radians, east +ve)
**     phi   double   geodetic latitude of the observer (radians)
**     hm    double   observer's height above sea level (metres)
**     xp    double   polar motion x-coordinate (radians)
**     yp    double   polar motion y-coordinate (radians)
**     tk    double   local ambient temperature (K; std=273.15)
**     pmb   double   local atmospheric pressure (mb; std=1013.25)
**     rh    double   local relative humidity (in the range 0-1)
**     wl    double   effective wavelength (micron, e.g. 0.55)
**     tlr   double   tropospheric lapse rate (K/metre, e.g. 0.0065)
**
**  Returned:
**     ri   double    CIRS right ascension (CEO-based, radians)
**     di   double    CIRS declination (radians)
**
**  Notes:
**
**  1)  Only the first character of the type argument is significant.
**      "R" or "r" indicates that ob1 and ob2 are the observed right
**      ascension and declination;  "H" or "h" indicates that they are
**      hour angle (west +ve) and declination;  anything else ("A" or
**      "a" is recommended) indicates that ob1 and ob2 are azimuth
**      (north zero, east 90 deg) and zenith distance.  (Zenith
**      distance is used rather than elevation in order to reflect the
**      fact that no allowance is made for depression of the horizon.)
**
**  2)  The accuracy of the result is limited by the corrections for
**      refraction.  Providing the meteorological parameters are
**      known accurately and there are no gross local effects, the
**      predicted CIRS RA,Dec should be within about 0.1 arcsec for a
**      zenith distance of less than 70 degrees.  Even at a topocentric
**      zenith distance of 90 degrees, the accuracy in elevation should
**      be better than 1 arcmin;  useful results are available for a
**      further 3 degrees, beyond which the slaRefro function returns a
**      fixed value of the refraction.  The complementary functions
**      slaI2o (or slaI2oqk)  and slaO2i (or slaO2iqk) are self-
**      consistent to better than 1 micro-arcsecond all over the
**      celestial sphere.
**
**  3)  It is advisable to take great care with units, as even
**      unlikely values of the input parameters are accepted and
**      processed in accordance with the models used.
**
**  4)  "Observed" Az,El means the position that would be seen by a
**      perfect theodolite located at the observer.  This is
**      related to the observed HA,Dec via the standard rotation, using
**      the geodetic latitude (corrected for polar motion), while the
**      observed HA and RA are related simply through the Earth rotation
**      angle and the site longitude.  "Observed" RA,Dec or HA,Dec thus
**      means the position that would be seen by a perfect equatorial
**      located at the observer and with its polar axis aligned to the
**      Earth's axis of rotation (n.b. not to the refracted pole).  By
**      removing from the observed place the effects of atmospheric
**      refraction and diurnal aberration, the geocentric celestial
**      intermediate RA,Dec is obtained.
**
**  5)  Frequently, ICRS RA,Dec rather than CIRS RA,Dec will be
**      required, in which case further transformations will be
**      necessary.  The slaI2c etc. functions will convert the CIRS
**      RA,Dec produced by the present function into an ICRS
**      astrometric place, by allowing for the Sun's gravitational
**      lens effect, annual aberration and precession-nutation.
**
**  6)  To convert to CIRS RA,Dec the coordinates read from a real
**      telescope, corrections would have to be applied for encoder zero
**      points, gear and encoder errors, tube flexure, the position of
**      the rotator axis and the pointing axis relative to it, non-
**      perpendicularity between the mounting axes, and finally for the
**      tilt of the azimuth or polar axis of the mounting (with
**      appropriate corrections for mount flexures).  Some telescopes
**      would, of course, exhibit other properties which would need to
**      be accounted for at the appropriate point in the sequence.
**
**  7)  This function takes time to execute, due mainly to the rigorous
**      integration used to evaluate the refraction.  For processing
**      multiple stars for one location and time, call slaI2opa once
**      followed by one call per star to slaO2iqk.  Where a range of
**      times within a limited period of a few hours is involved, and
**      the highest precision is not required, call slaI2opa once,
**      followed by a call to slaI2opat each time the time changes,
**      followed by one call per star to slaO2iqk.
**
**  8)  The date argument is UTC expressed as an MJD.  This is,
**      strictly speaking, improper, because of leap seconds.  However,
**      as long as the delta UT and the UTC are consistent there
**      are no difficulties, except during a leap second.  In this
**      case, the start of the 61st second of the final minute should
**      begin a new MJD day and the old pre-leap delta UT should
**      continue to be used.  As the 61st second completes, the MJD
**      should revert to the start of the day as, simultaneously,
**      the delta UTC changes by one second to its post-leap new value.
**
**  9)  The delta UT (UT1-UTC) is tabulated in IERS circulars and
**      elsewhere.  It increases by exactly one second at the end of
**      each UTC leap second, introduced in order to keep delta UT
**      within +/- 0.9 seconds.
**
**  10) IMPORTANT -- TAKE CARE WITH THE LONGITUDE SIGN CONVENTION.
**      The longitude required by the present function is east-positive,
**      in accordance with geographical convention (and right-handed).
**      In particular, note that the longitudes returned by the
**      slaObs function are west-positive, following astronomical
**      usage, and must be reversed in sign before use in the present
**      function.
**
**  11) The polar motion coordinates xp,yp can be obtained from IERS
**      bulletins.  The maximum amplitude is about 0.3 arcseconds.  If
**      xp,yp values are unavailable, use zeroes.  The xp,yp
**      coordinates are reckoned as follows:
**
**      . +ve xp means that the point on the geoid directly beneath
**        the CIP is in the hemisphere centered on longitude 90 deg.
**
**      . +ve yp means that the point on the geoid directly beneath
**        the CIP is in the hemisphere centered on longitude 270 deg.
**
**      Internally, the polar motion is stored in a form rotated onto
**      the local meridian.
**
**  12) The height above sea level of the observing station, hm,
**      can be obtained from the Astronomical Almanac (Section J
**      in the 1988 edition), or via the function slaObs.  If p,
**      the pressure in millibars, is available, an adequate
**      estimate of hm can be obtained from the expression
**
**            hm = -29.3 * tsl * log ( p / 1013.25 );
**
**      where tsl is the approximate sea-level air temperature in K
**      (See Astrophysical Quantities, C.W.Allen, 3rd edition, section
**      52).  Similarly, if the pressure p is not known, it can be
**      estimated from the height of the observing station, hm, as
**      follows:
**
**            p = 1013.25 * exp ( -hm / ( 29.3 * tsl ) );
**
**      Note, however, that the refraction is nearly proportional to
**      the pressure and that an accurate p value is important for
**      precise work.
**
**  Called:  slaI2opa, slaO2iqk
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaO2iqk ( char *type, double ob1, double ob2, IOpars *ioprms,
                double *ri, double *di )
/*
**  - - - - - - - - -
**   s l a O 2 i q k
**  - - - - - - - - -
**
**  Quick observed place to CIRS:  observed place at a ground based site
**  to CIRS RA,Dec, for sources distant from the solar system, given the
**  star-independent CIRS-to-observed parameters.
**
**  Given:
**     type   char[]    type of coordinates: 'R', 'H' or 'A' (see below)
**     ob1    double    observed Az, HA or RA (radians; Az is N=0,E=90)
**     ob2    double    observed ZD or Dec (radians)
**     ioprms IOpars*   star-independent CIRS-to-observed parameters:
**      along     double    longitude + s' + dERA(DUT) (radians)
**      phi       double    geodetic latitude (radians)
**      hm        double    height above sea level (meters)
**      xpl       double    polar motion xp wrt local meridian (radians)
**      ypl       double    polar motion yp wrt local meridian (radians)
**      sphi      double    sine and cosine of geodetic latitude
**      cphi      double    sine and cosine of geodetic latitude
**      diurab    double    magnitude of diurnal aberration vector
**      p         double    pressure (mb,hPa)
**      tk        double    ambient temperature (K)
**      rh        double    relative humidity (0-1)
**      tlr       double    tropospheric lapse rate (K per meter)
**      wl        double    wavelength (micrometers)
**      refa      double    refraction constant A (radians)
**      refb      double    refraction constant B (radians)
**      eral      double    "local" Earth Rotation Angle (radians)
**
**  Returned:
**     ri     double*   CIRS right ascension (CEO-based, radians)
**     di     double*   CIRS declination (radians)
**
**  Notes:
**
**  1)  Only the first character of the type argument is significant.
**      "R" or "r" indicates that ob1 and ob2 are the observed right
**      ascension and declination;  "H" or "h" indicates that they are
**      hour angle (west +ve) and declination;  anything else ("A" or
**      "a" is recommended) indicates that ob1 and ob2 are azimuth
**      (north zero, east 90 deg) and zenith distance.  (Zenith
**      distance is used rather than elevation in order to reflect the
**      fact that no allowance is made for depression of the horizon.)
**
**  2)  The accuracy of the result is limited by the corrections for
**      refraction.  Providing the meteorological parameters are
**      known accurately and there are no gross local effects, the
**      predicted CIRS RA,Dec should be within about 0.1 arcsec for a
**      zenith distance of less than 70 degrees.  Even at a topocentric
**      zenith distance of 90 degrees, the accuracy in elevation should
**      be better than 1 arcmin;  useful results are available for a
**      further 3 degrees, beyond which the slaRefro function returns a
**      fixed value of the refraction.  The complementary functions
**      slaI2o (or slaI2oqk) and slaO2i (or slaO2iqk) are self-
**      consistent to better than 1 micro-arcsecond all over the
**      celestial sphere.
**
**  3)  It is advisable to take great care with units, as even
**      unlikely values of the input parameters are accepted and
**      processed in accordance with the models used.
**
**  4)  "Observed" Az,El means the position that would be seen by a
**      perfect theodolite located at the observer.  This is
**      related to the observed HA,Dec via the standard rotation, using
**      the geodetic latitude (corrected for polar motion), while the
**      observed HA and RA are related simply through the Earth rotation
**      angle and the site longitude.  "Observed" RA,Dec or HA,Dec thus
**      means the position that would be seen by a perfect equatorial
**      located at the observer and with its polar axis aligned to the
**      Earth's axis of rotation (n.b. not to the refracted pole).  By
**      removing from the observed place the effects of atmospheric
**      refraction and diurnal aberration, the CIRS RA,Dec is obtained.
**
**  5)  Frequently, ICRS RA,Dec rather than CIRS RA,Dec will be
**      required, in which case further transformations will be
**      necessary.  The slaIbp etc. functions will convert the CIRS
**      RA,Dec produced by the present function into an ICRS astrometric
**      place, by allowing for the Sun's gravitational lens effect,
**      annual aberration and precession-nutation.
**
**  6)  To convert to CIRS RA,Dec the coordinates read from a real
**      telescope, corrections would have to be applied for encoder zero
**      points, gear and encoder errors, tube flexure, the position of
**      the rotator axis and the pointing axis relative to it, non-
**      perpendicularity between the mounting axes, and finally for the
**      tilt of the azimuth or polar axis of the mounting (with
**      appropriate corrections for mount flexures).  Some telescopes
**      would, of course, exhibit other properties which would need to
**      be accounted for at the appropriate point in the sequence.
**
**  7)  The star-independent CIRS-to-observed parameters in ioprms may
**      be computed by means of the slaI2opa function.  If nothing has
**      changed significantly except the time, the slaI2opat function
**      may be used to perform the requisite partial recomputation of
**      ioprms.
**
**  Called:  slaDcs2c, slaDcc2s, slaRefro, slaDranrm
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaOap ( char *type, double ob1, double ob2, double date,
              double dut, double elongm, double phim, double hm,
              double xp, double yp, double tdk, double pmb,
              double rh, double wl, double tlr,
              double *rap, double *dap )
/*
**  - - - - - - -
**   s l a O a p
**  - - - - - - -
**
**  Observed to apparent place
**
**  Given:
**     type   c*(*)  type of coordinates - "R", "H" or "A" (see below)
**     ob1    d      observed Az, HA or RA (radians; Az is N=0,E=90)
**     ob2    d      observed ZD or Dec (radians)
**     date   d      UTC date/time (modified Julian Date, JD-2400000.5)
**     dut    d      delta UT:  UT1-UTC (UTC seconds)
**     elongm d      mean longitude of the observer (radians, east +ve)
**     phim   d      mean geodetic latitude of the observer (radians)
**     hm     d      observer's height above sea level (metres)
**     xp     d      polar motion x-coordinate (radians)
**     yp     d      polar motion y-coordinate (radians)
**     tdk    d      local ambient temperature (K; std=273.15)
**     pmb    d      local atmospheric pressure (mb; std=1013.25)
**     rh     d      local relative humidity (in the range 0.0-1.0)
**     wl     d      effective wavelength (micron, e.g. 0.55)
**     tlr    d      tropospheric lapse rate (K/metre, e.g. 0.0065)
**
**  Returned:
**     rap    d      geocentric apparent right ascension
**     dap    d      geocentric apparent declination
**
**  Notes:
**
**  1)  Only the first character of the type argument is significant.
**      "R" or "r" indicates that obs1 and obs2 are the observed right
**      ascension and declination;  "H" or "h" indicates that they are
**      hour angle (west +ve) and declination;  anything else ("A" or
**      "a" is recommended) indicates that obs1 and obs2 are azimuth
**      (north zero, east 90 deg) and zenith distance.  (Zenith
**      distance is used rather than elevation in order to reflect the
**      fact that no allowance is made for depression of the horizon.)
**
**  2)  The accuracy of the result is limited by the corrections for
**      refraction.  Providing the meteorological parameters are
**      known accurately and there are no gross local effects, the
**      predicted observed RA,Dec should be within about 0.1 arcsec
**      for a zenith distance of less than 70 degrees.  Even at a
**      topocentric zenith distance of 90 degrees, the accuracy in
**      elevation should be better than 1 arcmin;  useful results
**      are available for a further 3 degrees, beyond which the
**      slaRefro function returns a fixed value of the refraction.
**      The complementary functions slaAop (or slaAopqk) and slaOap
**      (or slaOapqk) are self-consistent to better than 1 micro-
**      arcsecond all over the celestial sphere.
**
**  3)  It is advisable to take great care with units, as even
**      unlikely values of the input parameters are accepted and
**      processed in accordance with the models used.
**
**  4)  "Observed" Az,El means the position that would be seen by a
**      perfect theodolite located at the observer.  This is
**      related to the observed HA,Dec via the standard rotation, using
**      the geodetic latitude (corrected for polar motion), while the
**      observed HA and RA are related simply through the local
**      apparent ST.  "Observed" RA,Dec or HA,Dec thus means the
**      position that would be seen by a perfect equatorial located
**      at the observer and with its polar axis aligned to the
**      Earth's axis of rotation (n.b. not to the refracted pole).
**      By removing from the observed place the effects of
**      atmospheric refraction and diurnal aberration, the
**      geocentric apparent RA,Dec is obtained.
**
**  5)  Frequently, mean rather than apparent RA,Dec will be required,
**      in which case further transformations will be necessary.  The
**      slaAMP etc. functions will convert the apparent RA,Dec produced
**      by the present function into an "FK5" (J2000) mean place, by
**      allowing for the Sun's gravitational lens effect, annual
**      aberration, nutation and precession.  Should "FK4" (1950)
**      coordinates be needed, the functions slaFk425 etc. will also
**      need to be applied.
**
**  6)  To convert to apparent RA,Dec the coordinates read from a
**      real telescope, corrections would have to be applied for
**      encoder zero points, gear and encoder errors, tube flexure,
**      the position of the rotator axis and the pointing axis
**      relative to it, non-perpendicularity between the mounting
**      axes, and finally for the tilt of the azimuth or polar axis
**      of the mounting (with appropriate corrections for mount
**      flexures).  Some telescopes would, of course, exhibit other
**      properties which would need to be accounted for at the
**      appropriate point in the sequence.
**
**  7)  The star-independent apparent-to-observed-place parameters
**      in aoprms may be computed by means of the slaAoppa function.
**      If nothing has changed significantly except the time, the
**      slaAoppat function may be used to perform the requisite
**      partial recomputation of aoprms.
**
**  8)  The date argument is UTC expressed as an MJD.  This is,
**      strictly speaking, wrong, because of leap seconds.  However,
**      as long as the delta UT and the UTC are consistent there
**      are no difficulties, except during a leap second.  In this
**      case, the start of the 61st second of the final minute should
**      begin a new MJD day and the old pre-leap delta UT should
**      continue to be used.  As the 61st second completes, the MJD
**      should revert to the start of the day as, simultaneously,
**      the delta UTC changes by one second to its post-leap new value.
**
**  9)  The delta UT (UT1-UTC) is tabulated in IERS circulars and
**      elsewhere.  It increases by exactly one second at the end of
**      each UTC leap second, introduced in order to keep delta UT
**      within +/- 0.9 seconds.
**
**  10) IMPORTANT -- TAKE CARE WITH THE LONGITUDE SIGN CONVENTION.
**      The longitude required by the present function is east-positive,
**      in accordance with geographical convention (and right-handed).
**      In particular, note that the longitudes returned by the
**      slaObs function are west-positive, following astronomical
**      usage, and must be reversed in sign before use in the present
**      function.
**
**  11) The polar coordinates xp,yp can be obtained from IERS
**      circulars and equivalent publications.  The maximum amplitude
**      is about 0.3 arcseconds.  If xp,yp values are unavailable,
**      use xp=yp=0.0.  See page B60 of the 1988 Astronomical Almanac
**      for a definition of the two angles.
**
**  12) The height above sea level of the observing station, hm,
**      can be obtained from the Astronomical Almanac (Section J
**      in the 1988 edition), or via the function slaObs.  If p,
**      the pressure in millibars, is available, an adequate
**      estimate of hm can be obtained from the expression
**
**             hm = -29.3 * tsl * log ( p / 1013.25 );
**
**      where tsl is the approximate sea-level air temperature in K
**      (see Astrophysical Quantities, C.W.Allen, 3rd edition, section
**      52).  Similarly, if the pressure p is not known, it can be
**      estimated from the height of the observing station, hm, as
**      follows:
**
**             p = 1013.25 * exp ( -hm / ( 29.3 * tsl ) );
**
**      Note, however, that the refraction is nearly proportional to
**      the pressure and that an accurate p value is important for
**      precise work.
**
**  13) The azimuths etc. used by the present function are with respect
**      to the celestial pole.  Corrections from the terrestrial pole
**      can be computed using slaPolmo.
**
**  Called:  slaAoppa, slaOapqk
**
**  Last revision:   22 October 2006 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaOapqk ( char *type, double ob1, double ob2,
                double aoprms[14], double *rap, double *dap )
/*
**  - - - - - - - - -
**   s l a O a p q k
**  - - - - - - - - -
**
**  Quick observed to apparent place.
**
**  Given:
**     type   char        type of coordinates - "r", "h" or "a" (see below)
**     ob1    double      observed az, HA or RA (radians; az is n=0,e=90)
**     ob2    double      observed ZD or Dec (radians)
**     aoprms double[14]  star-independent apparent-to-observed parameters:
**
**       (0)      geodetic latitude (radians)
**       (1,2)    sine and cosine of geodetic latitude
**       (3)      magnitude of diurnal aberration vector
**       (4)      height (hm)
**       (5)      ambient temperature (t)
**       (6)      pressure (p)
**       (7)      relative humidity (rh)
**       (8)      wavelength (wl)
**       (9)      lapse rate (tlr)
**       (10,11)  refraction constants a and b (radians)
**       (12)     longitude + eqn of equinoxes + sidereal DUT (radians)
**       (13)     local apparent sidereal time (radians)
**
**  Returned:
**     *rap    double      geocentric apparent right ascension
**     *dap    double      geocentric apparent declination
**
**  Notes:
**
**   1)  Only the first character of the type argument is significant.
**       "R" or "r" indicates that obs1 and obs2 are the observed right
**       ascension and declination;  "H" or "h" indicates that they are
**       hour angle (west +ve) and declination;  anything else ("A" or
**       "a" is recommended) indicates that obs1 and obs2 are azimuth
**       (north zero, east 90 deg) and zenith distance.  (Zenith
**       distance is used rather than elevation in order to reflect the
**       fact that no allowance is made for depression of the horizon.)
**
**   2)  The accuracy of the result is limited by the corrections for
**       refraction.  Providing the meteorological parameters are
**       known accurately and there are no gross local effects, the
**       predicted observed RA,Dec should be within about 0.1 arcsec.
**       Even at a topocentric zenith distance of 90 degrees, the
**       accuracy in elevation should be better than 1 arcmin;  useful
**       results are available for a further 3 degrees, beyond which
**       the slaRefro function returns a fixed value of the refraction.
**       the complementary functions slaAop (or slaAopqk) and slaOap
**       (or slaOapqk) are self-consistent to better than 1 micro-
**       arcsecond all over the celestial sphere.
**
**   3)  It is advisable to take great care with units, as even
**       unlikely values of the input parameters are accepted and
**       processed in accordance with the models used.
**
**   5)  "Observed" az,el means the position that would be seen by a
**       perfect theodolite located at the observer.  This is
**       related to the observed HA,Dec via the standard rotation, using
**       the geodetic latitude (corrected for polar motion), while the
**       observed HA and RA are related simply through the local
**       apparent ST.  "Observed" RA,Dec or HA,Dec thus means the
**       position that would be seen by a perfect equatorial located
**       at the observer and with its polar axis aligned to the
**       Earth's axis of rotation (n.b. not to the refracted pole).
**       by removing from the observed place the effects of
**       atmospheric refraction and diurnal aberration, the
**       geocentric apparent RA,Dec is obtained.
**
**   5)  Frequently, mean rather than apparent RA,Dec will be required,
**       in which case further transformations will be necessary.  The
**       slaAmp etc. functions will convert the apparent RA,Dec produced
**       by the present function into an "FK5" (J2000) mean place, by
**       allowing for the Sun's gravitational lens effect, annual
**       aberration, nutation and precession.  Should "FK4" (1950)
**       coordinates be needed, the functions slaFk524 etc will also
**       need to be applied.
**
**   6)  To convert to apparent RA,Dec the coordinates read from a
**       real telescope, corrections would have to be applied for
**       encoder zero points, gear and encoder errors, tube flexure,
**       the position of the rotator axis and the pointing axis
**       relative to it, non-perpendicularity between the mounting
**       axes, and finally for the tilt of the azimuth or polar axis
**       of the mounting (with appropriate corrections for mount
**       flexures).  Some telescopes would, of course, exhibit other
**       properties which would need to be accounted for at the
**       appropriate point in the sequence.
**
**   7)  The star-independent apparent-to-observed-place parameters
**       in aoprms may be computed by means of the slaAoppa function.
**       If nothing has changed significantly except the time, the
**       slaAoppat function may be used to perform the requisite
**       partial recomputation of aoprms.
**
**   8)  The azimuths etc. used by the present function are with respect
**       to the celestial pole.  Corrections from the terrestrial pole
**       can be computed using slaPolmo.
**
**  Called:  slaDcs2c, slaDcc2s, slaRefro, slaDranrm
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaObs ( int n, char *c, char *name, double *w, double *p, double *h )
/*
**  - - - - - - -
**   s l a O b s
**  - - - - - - -
**
**  Parameters of selected groundbased observing stations.
**
**  Given:
**     n       int     number specifying observing station
**
**  Either given or returned
**    *c       char    identifier specifying observing station
**
**  Returned:
**    *name    char    name of specified observing station
**    *w       double  longitude (radians, West +ve)
**    *p       double  geodetic latitude (radians, North +ve)
**    *h       double  height above sea level (metres)
**
**  Notes:
**
**     Station identifiers may be up to 10 characters long
**     (plus string terminator), and station names may be up to
**     40 characters long (plus string terminator).  Leading or
**     trailing spaces are not supported.
**
**     c and n are alternative ways of specifying the observing
**     station.  The c option, which is the most generally useful,
**     may be selected by specifying an n value of zero or less.
**     If n is 1 or more, the parameters of the nth station
**     in the currently supported list are interrogated (n=1
**     meaning the first station in the list), and the station
**     identifier c is returned as well as name, w, p and h.
**
**     If the station parameters are not available, either because
**     the station identifier c is not recognized, or because an
**     n value greater than the number of stations supported is
**     given, a name of "?" is returned and c, w, p and h are left
**     in their current states.
**
**     Programs can obtain a list of all currently supported
**     stations by calling the function repeatedly, with n=1,2,3...
**     When name="?" is seen, the list of stations has been
**     exhausted.
**
**     Station numbers, identifiers, names and other details are
**     subject to change and should not be hardwired into
**     application programs.
**
**     All station identifiers c are uppercase only;  lowercase
**     characters must be converted to uppercase by the calling
**     program.  The station names returned may contain both upper-
**     and lowercase.  All characters up to the first space are
**     checked;  thus an abbreviated ID will return the parameters
**     for the first station in the list which matches the
**     abbreviation supplied, and no station in the list will ever
**     contain embedded spaces.  c must not have leading spaces.
**
**     IMPORTANT -- BEWARE OF THE LONGITUDE SIGN CONVENTION.  The
**     longitude returned by slaObs is west-positive in accordance
**     with astronomical usage.  However, this sign convention is
**     left-handed and is the opposite of the one used by geographers;
**     elsewhere in slalib the preferable east-positive convention is
**     used.  In particular, note that for use in slaAop, slaAoppa
**     and slaOap the sign of the longitude must be reversed.
**
**     Users are urged to inform the author of any improvements
**     they would like to see made.  For example:
**
**         typographical corrections
**         more accurate parameters
**         better station identifiers or names
**         additional stations
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaPa ( double ha, double dec, double phi )
/*+
**  - - - - - -
**   s l a P a
**  - - - - - -
**
**  HA, Dec to Parallactic Angle.
**
**  (double precision)
**
**  Given:
**     ha     d     hour angle in radians (geocentric apparent)
**     dec    d     declination in radians (geocentric apparent)
**     phi    d     observatory latitude in radians (geodetic)
**
**  The result is in the range -pi to +pi
**
**  Notes:
**
**  1)  The parallactic angle at a point in the sky is the position
**      angle of the vertical, i.e. the angle between the direction to
**      the pole and to the zenith.  In precise applications care must
**      be taken only to use geocentric apparent HA,Dec and to consider
**      separately the effects of atmospheric refraction and telescope
**      mount errors.
**
**  2)  At the pole a zero result is returned.
**
**  Last revision:   16 August 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaPav ( float v1 [ 3 ], float v2 [ 3 ] )
/*
**  - - - - - - -
**   s l a P a v
**  - - - - - - -
**
**  Position angle of one celestial direction with respect to another.
**
**  (single precision)
**
**  Given:
**     v1    float[3]    direction cosines of one point
**     v2    float[3]    direction cosines of the other point
**
**  (The coordinate frames correspond to RA,Dec, Long,Lat etc.)
**
**  The result is the bearing (position angle), in radians, of point
**  v2 with respect to point v1.  It is in the range +/- pi.  The
**  sense is such that if v2 is a small distance east of v1, the
**  bearing is about +pi/2.  Zero is returned if the two points
**  are coincident.
**
**  The vectors v1 and v2 need not be unit vectors.
**
**  The function slaBear performs an equivalent function except
**  that the points are specified in the form of spherical
**  coordinates.
**
**  Called:  slaDpav
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPcd ( double disco, double *x, double *y )
/*
**  - - - - - - -
**   s l a P c d
**  - - - - - - -
**
**  Apply pincushion/barrel distortion to a tangent-plane [x,y].
**
**  Given:
**     disco    double      pincushion/barrel distortion coefficient
**     x,y      double      tangent-plane coordinates
**
**  Returned:
**     *x,*y    double      distorted coordinates
**
**  Notes:
**
**   1)  The distortion is of the form rp = r*(1 + c*r**2), where r is
**       the radial distance from the tangent point, c is the disco
**       argument, and rp is the radial distance in the presence of
**       the distortion.
**
**   2)  For pincushion distortion, c is +ve;
**       For barrel distortion, c is -ve.
**
**   3)  For x,y in units of one projection radius (in the case of
**       a photographic plate, the focal length), the following
**       disco values apply:
**
**           geometry          disco
**
**           astrograph         0.0
**           schmidt           -0.3333
**           AAT pf doublet  +147.069
**           AAT pf triplet  +178.585
**           AAT f/8          +21.20
**           JKT f/8          +13.32
**
**    4)  There is a companion function, slaUnpcd, which performs the
**        inverse operation.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPda2h ( double p, double d, double a,
                double *h1, int *j1, double *h2, int *j2 )
/*
**  - - - - - - - - -
**   s l a P d a 2 h
**  - - - - - - - - -
**
**  Hour Angle corresponding to a given azimuth
**
**  (double precision)
**
**  Given:
**     p           double      latitude
**     d           double      declination
**     a           double      azimuth
**
**  Returned:
**     *h1         double      hour angle:  first solution if any
**     *j1         int         flag: 0 = solution 1 is valid
**     *h2         double      hour angle:  first solution if any
**     *j2         int         flag: 0 = solution 2 is valid
**
**  Defined in slamac.h:  DPI, DPIBY2
**
**  Last revision:   24 November 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPdq2h ( double p, double d, double q,
                double *h1, int *j1, double *h2, int *j2 )
/*
**  - - - - - - - - -
**   s l a P d q 2 h
**  - - - - - - - - -
**
**  Hour Angle corresponding to a given parallactic angle
**
**  (double precision)
**
**  Given:
**     p           double      latitude
**     d           double      declination
**     q           double      parallactic angle
**
**  Returned:
**     *h1         double      hour angle:  first solution if any
**     *j1         int         flag: 0 = solution 1 is valid
**     *h2         double      hour angle:  first solution if any
**     *j2         int         flag: 0 = solution 2 is valid
**
**  Called:  slaDrange
**
**  Defined in slamac.h:  DPI, DPIBY2
**
**  Last revision:   24 November 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPermut ( int n, int istate[], int iorder[], int* j )
/*
**  - - - - - - - - - -
**   s l a P e r m u t
**  - - - - - - - - - -
**
**  Generate the next permutation of a specified number of items.
**
**  Given:
**     n        int      number of items:  there will be n! permutations
**
**  Given and returned:
**     istate   int[n]   state, istate[0]=-1 to initialize
**
**  Returned:
**     istate   int[n]   state, updated ready for next time
**     iorder   int[n)   next permutation of numbers 1,2,...,n
**     *j       int      status: -1 = illegal n (zero or less is illegal)
**                                0 = OK
**                               +1 = no more permutations available
**
**  Notes:
**
**  1) This function returns, in the iorder array, the integers 1 to n
**     inclusive, in an order that depends on the current contents of
**     the istate array.  Before calling the function for the first
**     time, the caller must set the first element of the istate array
**     to -1 (any negative number will do) to cause the istate array
**     to be fully initialized.
**
**  2) The first permutation to be generated is:
**
**          iorder[0]=n, iorder[1]=n-1, ..., iorder[n-1]=1
**
**     This is also the permutation returned for the "finished"
**     (j=1) case.
**
**     The final permutation to be generated is:
**
**          iorder[0]=1, iorder[1]=2, ..., iorder[n-1]=n
**
**  3) If the "finished" (j=1) status is ignored, the function continues
**     to deliver permutations, the pattern repeating every n! calls.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPertel (int jform, double date0, double date1,
                double epoch0, double orbi0, double anode0,
                double perih0, double aorq0, double e0, double am0,
                double *epoch1, double *orbi1, double *anode1,
                double *perih1, double *aorq1, double *e1, double *am1,
                int *jstat )
/*
**  - - - - - - - - - -
**   s l a P e r t e l
**  - - - - - - - - - -
**
**  Update the osculating orbital elements of an asteroid or comet by
**  applying planetary perturbations.
**
**  Given (format and dates):
**     jform   int      choice of element set (2 or 3; Note 1)
**     date0   double   date of osculation (TT MJD) for the given elements
**     date1   double   date of osculation (TT MJD) for the updated elements
**
**  Given (the unperturbed elements):
**     epoch0  double   epoch (TT MJD) of the given element set (Note 2)
**     orbi0   double   inclination (radians)
**     anode0  double   longitude of the ascending node (radians)
**     perih0  double   argument of perihelion (radians)
**     aorq0   double   mean distance or perihelion distance (AU)
**     e0      double   eccentricity
**     am0     double   mean anomaly (radians, jform=2 only)
**
**  Returned (the updated elements):
**     epoch1  double*  epoch (TT MJD) of the updated element set (Note 2)
**     orbi1   double*  inclination (radians)
**     anode1  double*  longitude of the ascending node (radians)
**     perih1  double*  argument of perihelion (radians)
**     aorq1   double*  mean distance or perihelion distance (AU)
**     e1      double*  eccentricity
**     am1     double*  mean anomaly (radians, jform=2 only)
**
**  Returned (status flag):
**     jstat   int*     status: +102 = warning, distant epoch
**                              +101 = warning, large timespan ( > 100 years)
**                         +1 to +10 = coincident with planet (Note 6)
**                                 0 = OK
**                                -1 = illegal jform
**                                -2 = illegal e0
**                                -3 = illegal aorq0
**                                -4 = internal error
**                                -5 = numerical error
**
**  Notes:
**
**  1  Two different element-format options are available:
**
**     Option jform=2, suitable for minor planets:
**
**     epoch   = epoch of elements (TT MJD)
**     orbi    = inclination i (radians)
**     anode   = longitude of the ascending node, big omega (radians)
**     perih   = argument of perihelion, little omega (radians)
**     aorq    = mean distance, a (AU)
**     e       = eccentricity, e
**     am      = mean anomaly M (radians)
**
**     Option jform=3, suitable for comets:
**
**     epoch   = epoch of perihelion (TT MJD)
**     orbi    = inclination i (radians)
**     anode   = longitude of the ascending node, big omega (radians)
**     perih   = argument of perihelion, little omega (radians)
**     aorq    = perihelion distance, q (AU)
**     e       = eccentricity, e
**
**  2  date0, date1, epoch0 and epoch1 are all instants of time in
**     the TT timescale (formerly Ephemeris Time, ET), expressed
**     as Modified Julian Dates (JD-2400000.5).
**
**     date0 is the instant at which the given (i.e. unperturbed)
**     osculating elements are correct.
**
**     date1 is the specified instant at which the updated osculating
**     elements are correct.
**
**     epoch0 and epoch1 will be the same as date0 and date1
**     (respectively) for the jform=2 case, normally used for minor
**     planets.  For the jform=3 case, the two epochs will refer to
**     perihelion passage and so will not, in general, be the same as
**     date0 and/or date1 though they may be similar to one another.
**
**  3  The elements are with respect to the J2000 ecliptic and equinox.
**
**  4  Unused elements (am0 and am1 for jform=3) are not accessed.
**
**  5  See the slaPertue function for details of the algorithm used.
**
**  6  This function is not intended to be used for major planets, which
**     is why jform=1 is not available and why there is no opportunity
**     to specify either the longitude of perihelion or the daily
**     motion.  However, if jform=2 elements are somehow obtained for a
**     major planet and supplied to the function, sensible results will,
**     in fact, be produced.  This happens because the slaPertue
**     function that is called to perform the calculations checks the
**     separation between the body and each of the planets and
**     interprets a suspiciously small value (1E-3 AU) as an attempt to
**     apply it to the planet concerned.  If this condition is detected,
**     the contribution from that planet is ignored, and the status is
**     set to the planet number (1-10 = Mercury, Venus, EMB, Mars,
**     Jupiter, Saturn, Uranus, Neptune, Earth, Moon) as a warning.
**
**  Reference:
**
**     Sterne, Theodore E., "An Introduction to Celestial Mechanics",
**     Interscience Publishers Inc., 1960.  Section 6.7, p199.
**
**  Called:  slaEl2ue, slaPertue, slaUe2el
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPertue ( double date, double u[], int *jstat )
/*
**  - - - - - - - - - -
**   s l a P e r t u e
**  - - - - - - - - - -
**
**  Update the universal elements of an asteroid or comet by applying
**  planetary perturbations.
**
**  Given:
**     date    double     final epoch (TT MJD) for the updated elements
**
**  Given and returned:
**     u       double[13] universal orbital elements (Note 1)
**
**                [0] combined mass (M+m)
**                [1] total energy of the orbit (alpha)
**                [2] reference (osculating) epoch (t0)
**              [3-5] position at reference epoch (r0)
**              [6-8] velocity at reference epoch (v0)
**                [9] heliocentric distance at reference epoch
**               [10] r0.v0
**               [11] date (t)
**               [12] universal eccentric anomaly (psi) of date, approx
**
**  Returned:
**     jstat   int*      status:
**                         +102 = warning, distant epoch
**                         +101 = warning, large timespan ( > 100 years)
**                    +1 to +10 = coincident with planet (Note 5)
**                            0 = OK
**                           -1 = numerical error
**
**  Called:  slaEpj, slaPlanet, slaPv2ue, slaUe2pv, slaEpv, slaPrec,
**           slaDmoon, slaDmxv
**
**  Notes:
**
**  1  The "universal" elements are those which define the orbit for the
**     purposes of the method of universal variables (see reference 2).
**     They consist of the combined mass of the two bodies, an epoch,
**     and the position and velocity vectors (arbitrary reference frame)
**     at that epoch.  The parameter set used here includes also various
**     quantities that can, in fact, be derived from the other
**     information.  This approach is taken to avoiding unnecessary
**     computation and loss of accuracy.  The supplementary quantities
**     are (i) alpha, which is proportional to the total energy of the
**     orbit, (ii) the heliocentric distance at epoch, (iii) the
**     outwards component of the velocity at the given epoch, (iv) an
**     estimate of psi, the "universal eccentric anomaly" at a given
**     date and (v) that date.
**
**  2  The universal elements are with respect to the J2000 equator and
**     equinox.
**
**  3  The epochs date, u[2] and u[11] are all Modified Julian Dates
**     (JD-2400000.5).
**
**  4  The algorithm is a simplified form of Encke's method.  It takes
**     as a basis the unperturbed motion of the body, and numerically
**     integrates the perturbing accelerations from the major planets.
**     The expression used is essentially Sterne's 6.7-2 (reference 1).
**     Everhart and Pitkin (reference 2) suggest rectifying the orbit at
**     each integration step by propagating the new perturbed position
**     and velocity as the new universal variables.  In the present
**     function the orbit is rectified less frequently than this, in
**     order to gain a slight speed advantage.  However, the
**     rectification is done directly in terms of position and velocity,
**     as suggested by Everhart and Pitkin, bypassing the use of
**     conventional orbital elements.
**
**     The f(q) part of the full Encke method is not used.  The purpose
**     of this part is to avoid subtracting two nearly equal quantities
**     when calculating the "indirect member", which takes account of
**     the small change in the Sun's attraction due to the slightly
**     displaced position of the perturbed body.  A simpler, direct
**     calculation in double precision proves to be faster and not
**     significantly less accurate.
**
**     Apart from employing a variable timestep, and occasionally
**     "rectifying the orbit" to keep the indirect member small, the
**     integration is done in a fairly straightforward way.  The
**     acceleration estimated for the middle of the timestep is assumed
**     to apply throughout that timestep;  it is also used in the
**     extrapolation of the perturbations to the middle of the next
**     timestep, to predict the new disturbed position.  There is no
**     iteration within a timestep.
**
**     Measures are taken to reach a compromise between execution time
**     and accuracy.  The starting-point is the goal of achieving
**     arcsecond accuracy for ordinary minor planets over a ten-year
**     timespan.  This goal dictates how large the timesteps can be,
**     which in turn dictates how frequently the unperturbed motion has
**     to be recalculated from the osculating elements.
**
**     Within predetermined limits, the timestep for the numerical
**     integration is varied in length in inverse proportion to the
**     magnitude of the net acceleration on the body from the major
**     planets.
**
**     The numerical integration requires estimates of the major-planet
**     motions.  Approximate positions for the planets are obtained from
**     the function slaPlanet.  Two levels of interpolation are used, to
**     enhance speed without significantly degrading accuracy.  At a low
**     frequency, the function slaPlanet is called to generate updated
**     position+velocity "state vectors".  The only task remaining to be
**     carried out at the full frequency (i.e. at each integration step)
**     is to use the state vectors to extrapolate the planetary
**     positions.  In place of a strictly linear extrapolation, some
**     allowance is made for the curvature of the orbit by scaling back
**     the radius vector as the linear extrapolation goes off at a
**     tangent.
**
**     Various other approximations are made.  For example,
**     perturbations by Pluto and the minor planets are neglected and
**     relativistic effects are not taken into account.
**
**     In the interests of simplicity, the background calculations for
**     the major planets are carried out en masse.  The mean elements
**     and state vectors for all the planets are refreshed at the same
**     time, without regard for orbit curvature, mass or proximity.
**
**     The Earth-Moon system is treated as a single body when the body
**     is distant but as separate bodies when closer to the EMB than the
**     parameter RNE, which incurs a time penalty but improves accuracy
**     for near-Earth objects.
**
**  5  This function is not intended to be used for major planets.
**     However, if major-planet elements are supplied, sensible results
**     will, in fact, be produced.  This happens because the function
**     checks the separation between the body and each of the planets
**     and interprets a suspiciously small value (0.001 AU) as an
**     attempt to apply the function to the planet concerned.  If this
**     condition is detected, the contribution from that planet is
**     ignored, and the status is set to the planet number (1-10 =
**     Mercury, Venus, EMB, Mars, Jupiter, Saturn, Uranus, Neptune,
**     Earth, Moon) as a warning.
**
**  References:
**
**     1  Sterne, Theodore E., "An Introduction to Celestial Mechanics",
**        Interscience Publishers Inc., 1960.  Section 6.7, p199.
**
**     2  Everhart, E. & Pitkin, E.T., Am.J.Phys. 51, 712, 1983.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPfw ( double date,
              double *gamb, double *phib, double *psib, double *epsa )
/*
**  - - - - - - -
**   s l a P f w
**  - - - - - - -
**
**  Precession angles, IAU 2006 (Fukushima-Williams 4-angle
**  formulation).
**
**  Given:
**     date     double    TDB Modified Julian Date
**
**  Returned:
**     gamb     double*   F-W angle gamma_bar (radians)
**     phib     double*   F-W angle phi_bar (radians)
**     psib     double*   F-W angle psi_bar (radians)
**     epsa     double*   F-W angle epsilon_A (radians)
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT will do.
**
**  2) Naming the following points:
**
**           e = J2000 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
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPlanel ( double date, int jform, double epoch, double orbinc,
                 double anode, double perih, double aorq, double e,
                 double aorl, double dm, double pv[6], int* jstat )
/*
**  - - - - - - - - - -
**   s l a P l a n e l
**  - - - - - - - - - -
**
**  Heliocentric position and velocity of a planet, asteroid or comet,
**  starting from orbital elements.
**
**  Given:
**     date    double     date, Modified Julian Date (JD - 2400000.5)
**     jform   int        choice of element set (1-3; Note 3)
**     epoch   double     epoch of elements (TT MJD)
**     orbinc  double     inclination (radians)
**     anode   double     longitude of the ascending node (radians)
**     perih   double     longitude or argument of perihelion (radians)
**     aorq    double     mean distance or perihelion distance (AU)
**     e       double     eccentricity
**     aorl    double     mean anomaly or longitude (radians, jform=1,2 only)
**     dm      double     daily motion (radians, jform=1 only)
**
**  Returned:
**     pv      double[6]  heliocentric x,y,z,xdot,ydot,zdot of date,
**                         J2000 equatorial triad (AU,AU/s)
**     jstat   int*       status:  0 = OK
**                                -1 = illegal jform
**                                -2 = illegal e
**                                -3 = illegal aorq
**                                -4 = illegal dm
**                                -5 = numerical error
**
**  Called:  slaEl2ue, slaUe2pv
**
**  Notes
**
**  1  The argument "date" is the instant for which the prediction is
**     required.  It is in the TT timescale (formerly Ephemeris Time,
**     ET) and is a Modified Julian Date (JD-2400000.5).
**
**  2  The elements are with respect to the J2000 ecliptic and equinox.
**
**  3  A choice of three different element-set options is available:
**
**     Option jform = 1, suitable for the major planets:
**
**       epoch  = epoch of elements (TT MJD)
**       orbinc = inclination i (radians)
**       anode  = longitude of the ascending node, big omega (radians)
**       perih  = longitude of perihelion, curly pi (radians)
**       aorq   = mean distance, a (AU)
**       e      = eccentricity, e (range 0 to <1)
**       aorl   = mean longitude L (radians)
**       dm     = daily motion (radians)
**
**     Option jform = 2, suitable for minor planets:
**
**       epoch  = epoch of elements (TT MJD)
**       orbinc = inclination i (radians)
**       anode  = longitude of the ascending node, big omega (radians)
**       perih  = argument of perihelion, little omega (radians)
**       aorq   = mean distance, a (AU)
**       e      = eccentricity, e (range 0 to <1)
**       aorl   = mean anomaly M (radians)
**
**     Option jform = 3, suitable for comets:
**
**       epoch  = epoch of elements and perihelion (TT MJD)
**       orbinc = inclination i (radians)
**       anode  = longitude of the ascending node, big omega (radians)
**       perih  = argument of perihelion, little omega (radians)
**       aorq   = perihelion distance, q (AU)
**       e      = eccentricity, e (range 0 to 10)
**
**     Unused arguments (dm for jform=2, aorl and dm for jform=3) are
**     not accessed.
**
**  4  Each of the three element sets defines an unperturbed
**     heliocentric orbit.  For a given epoch of observation, the
**     position of the body in its orbit can be predicted from these
**     elements, which are called "osculating elements", using standard
**     two-body analytical solutions.  However, due to planetary
**     perturbations, a given set of osculating elements remains usable
**     for only as long as the unperturbed orbit that it describes is an
**     adequate approximation to reality.  Attached to such a set of
**     elements is a date called the "osculating epoch", at which the
**     elements are, momentarily, a perfect representation of the
**     instantaneous position and velocity of the body.
**
**     Therefore, for any given problem there are up to three different
**     epochs in play, and it is vital to distinguish clearly between
**     them:
**
**     . The epoch of observation:  the moment in time for which the
**       position of the body is to be predicted.
**
**     . The epoch defining the position of the body:  the moment in
**       time at which, in the absence of purturbations, the specified
**       position (mean longitude, mean anomaly, or perihelion) is
**       reached.
**
**     . The osculating epoch:  the moment in time at which the given
**       elements are correct.
**
**     For the major-planet and minor-planet cases it is usual to make
**     the epoch that defines the position of the body the same as the
**     epoch of osculation.  Thus, only two different epochs are
**     involved:  the epoch of the elements and the epoch of
**     observation.
**
**     For comets, the epoch of perihelion fixes the position in the
**     orbit and in general a different epoch of osculation will be
**     chosen.  Thus, all three types of epoch are involved.
**
**     For the present function:
**
**     . The epoch of observation is the argument date.
**
**     . The epoch defining the position of the body is the argument
**       epoch.
**
**     . The osculating epoch is not used and is assumed to be close
**       enough to the epoch of observation to deliver adequate
**       accuracy.  If not, a preliminary call to slaPertel may be
**       used to update the element-set (and its associated osculating
**       epoch) by applying planetary perturbations.
**
**  5  The reference frame for the result is with respect to the mean
**     equator and equinox of epoch J2000.
**
**  6  The algorithm was originally adapted from the EPHSLA program
**     of D.H.P.Jones (private communication, 1996).  The method is
**     based on Stumpff's Universal Variables.
**
**  Reference:  Everhart, E. & Pitkin, E.T., Am.J.Phys. 51, 712, 1983.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPlanet ( double date, int np, double pv[6], int *jstat )
/*
**  - - - - - - - - - -
**   s l a P l a n e t
**  - - - - - - - - - -
**
**  Approximate heliocentric position and velocity of a specified
**  planet.
**
**  Given:
**     date     double      TDB (loosely ET) as a Modified Julian Date
**                                                  (JD-2400000.5)
**     np       int         body (1=Mercury, 2=Venus, 3=EMB,...9=Pluto)
**
**  Returned:
**     pv       double[6]   heliocentric x,y,z,xdot,ydot,zdot, J2000
**                                           equatorial triad (AU,AU/s)
**
**     *jstat   int         status: +1 = warning: date outside 1000-3000
**     *jstat   int         status:  0 = OK
**                                  -1 = illegal NP (outside 1-9)
**                                  -2 = solution didn't converge
**
**  Called:  slaPlanel
**
**  Notes
**
**  1  The epoch, date, is in the TDB timescale and is a Modified
**     Julian Date (JD-2400000.5).
**
**  2  The reference frame is equatorial and is with respect to the
**     mean equinox and ecliptic of epoch J2000.
**
**  3  If an np value outside the range 1-9 is supplied, an error
**     status (jstat = -1) is returned and the pv vector set to zeroes.
**
**  4  The algorithm for obtaining the mean elements of the planets
**     (Mercury to Neptune) is due to J.L. Simon, P. Bretagnon,
**     J. Chapront, M. Chapront-Touze, G. Francou and J. Laskar
**     (Bureau des Longitudes, Paris).  The (completely different)
**     algorithm for calculating the ecliptic coordinates of the dwarf
**     planet Pluto is by Meeus.
**
**  5  Comparisons of the present function with the JPL DE200 ephemeris
**     give the following RMS errors over the interval 1960-2025:
**
**                      position (km)     speed (metre/sec)
**
**        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
**
**     From comparisons with DE102, Simon et al quote the following
**     longitude accuracies over the interval 1800-2200:
**
**        Mercury                 4"
**        Venus                   5"
**        EMB                     6"
**        Mars                   17"
**        Jupiter                71"
**        Saturn                 81"
**        Uranus                 86"
**        Neptune                11"
**
**     In the case of Pluto, Meeus quotes an accuracy of 0.6 arcsec
**     in longitude and 0.2 arcsec in latitude for the period
**     1885-2099.
**
**     For all except Pluto, over the period 1000-3000 the accuracy
**     is better than 1.5 times that over 1800-2200.  Outside the
**     period 1000-3000 the accuracy declines.  For Pluto the
**     accuracy declines rapidly outside the period 1885-2099.
**     Outside these ranges (1885-2099 for Pluto, 1000-3000 for
**     the rest) a "date out of range" warning status (JSTAT=+1)
**     is returned.
**
**  6  The algorithms for (i) Mercury through Neptune and (ii) Pluto
**     are completely independent.  In the Mercury through Neptune
**     case, the present SLALIB C implementation follows the original
**     Simon et al Fortran code closely, and delivers essentially
**     the same results.  The changes are these:
**
**     *  The date is supplied as a Modified Julian Date rather
**        than a Julian Date (MJD = JD - 2400000.5).
**
**     *  The result is returned only in equatorial Cartesian form;
**        the ecliptic longitude, latitude and radius vector are not
**        returned.
**
**     *  The velocity is in AU per second, not AU per day.
**
**     *  Different error/warning status values are used.
**
**     *  Kepler's equation is not solved inline.
**
**     *  Polynomials in T are nested to minimize rounding errors.
**
**     *  Explicit double-precision constants are used to avoid
**        mixed-mode expressions.
**
**  7  For np=3 the result is for the Earth-Moon Barycentre.  To
**     obtain the heliocentric position and velocity of the Earth,
**     either use the SLALIB function slaEvp (or slaEpv) or use slaDmoon
**     and subtract 0.012150581 times the geocentric Moon vector from
**     the EMB vector produced by the present function.  (The Moon
**     vector should be precessed to J2000 first, but this can
**     be omitted for modern epochs without introducing significant
**     inaccuracy.)
**
**  References:  Simon et al., Astron. Astrophys. 282, 663 (1994).
**               Meeus, Astronomical Algorithms, Willmann-Bell (1991).
**
**  Defined in slamac.h:  D2PI, DAS2R, DD2R, dmod
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPlante ( double date, double elong, double phi, int jform,
                 double epoch, double orbinc, double anode, double perih,
                 double aorq, double e, double aorl, double dm,
                 double *ra, double *dec, double *r, int *jstat )
/*
**  - - - - - - - - - -
**   s l a P l a n t e
**  - - - - - - - - - -
**
**  Topocentric apparent RA,Dec of a Solar-System object whose
**  heliocentric orbital elements are known.
**
**  Given:
**     date    double   MJD of observation (JD - 2400000.5, Notes 1,5)
**     elong   double   observer's east longitude (radians, Note 2)
**     phi     double   observer's geodetic latitude (radians, Note 2)
**     jform   int      choice of element set (1-3; Notes 3-6)
**     epoch   double   epoch of elements (TT MJD, Note 5)
**     orbinc  double   inclination (radians)
**     anode   double   longitude of the ascending node (radians)
**     perih   double   longitude or argument of perihelion (radians)
**     aorq    double   mean distance or perihelion distance (AU)
**     e       double   eccentricity
**     aorl    double   mean anomaly or longitude (radians, jform=1,2 only)
**     dm      double   daily motion (radians, jform=1 only )
**
**  Returned:
**     ra,dec  double   RA, Dec (topocentric apparent, radians)
**     r       double   distance from observer (AU)
**     jstat   int      status:  0 = OK
**                              -1 = illegal jform
**                              -2 = illegal e
**                              -3 = illegal aorq
**                              -4 = illegal dm
**                              -5 = numerical error
**
**  Notes:
**
**  1  The argument "date" is the instant for which the prediction is
**     required.  It is in the TT timescale (formerly Ephemeris Time,
**     ET) and is a Modified Julian Date (JD-2400000.5).
**
**  2  The longitude and latitude allow correction for geocentric
**     parallax.  This is usually a small effect, but can become
**     important for near-Earth asteroids.  Geocentric positions can be
**     generated by appropriate use of the functions slaEvp (or slaEpv)
**     and slaPlanel.
**
**  3  The elements are with respect to the J2000 ecliptic and equinox.
**
**  4  A choice of three different element-set options is available:
**
**     Option jform = 1, suitable for the major planets:
**
**       epoch  = epoch of elements (TT MJD)
**       orbinc = inclination i (radians)
**       anode  = longitude of the ascending node, big omega (radians)
**       perih  = longitude of perihelion, curly pi (radians)
**       aorq   = mean distance, a (AU)
**       e      = eccentricity, e (range 0 to <1)
**       aorl   = mean longitude L (radians)
**       dm     = daily motion (radians)
**
**     Option jform = 2, suitable for minor planets:
**
**       epoch  = epoch of elements (TT MJD)
**       orbinc = inclination i (radians)
**       anode  = longitude of the ascending node, big omega (radians)
**       perih  = argument of perihelion, little omega (radians)
**       aorq   = mean distance, a (AU)
**       e      = eccentricity, e (range 0 to <1)
**       aorl   = mean anomaly M (radians)
**
**     Option jform = 3, suitable for comets:
**
**       epoch  = epoch of elements and perihelion (TT MJD)
**       orbinc = inclination i (radians)
**       anode  = longitude of the ascending node, big omega (radians)
**       perih  = argument of perihelion, little omega (radians)
**       aorq   = perihelion distance, q (AU)
**       e      = eccentricity, e (range 0 to 10)
**
**     Unused arguments (dm for jform=2, aorl and dm for jform=3) are
**     not accessed.
**
**  5  Each of the three element sets defines an unperturbed
**     heliocentric orbit.  For a given epoch of observation, the
**     position of the body in its orbit can be predicted from these
**     elements, which are called "osculating elements", using standard
**     two-body analytical solutions.  However, due to planetary
**     perturbations, a given set of osculating elements remains usable
**     for only as long as the unperturbed orbit that it describes is an
**     adequate approximation to reality.  Attached to such a set of
**     elements is a date called the "osculating epoch", at which the
**     elements are, momentarily, a perfect representation of the
**     instantaneous position and velocity of the body.
**
**     Therefore, for any given problem there are up to three different
**     epochs in play, and it is vital to distinguish clearly between
**     them:
**
**     . The epoch of observation:  the moment in time for which the
**       position of the body is to be predicted.
**
**     . The epoch defining the position of the body:  the moment in
**       time at which, in the absence of purturbations, the specified
**       position (mean longitude, mean anomaly, or perihelion) is
**       reached.
**
**     . The osculating epoch:  the moment in time at which the given
**       elements are correct.
**
**     For the major-planet and minor-planet cases it is usual to make
**     the epoch that defines the position of the body the same as the
**     epoch of osculation.  Thus, only two different epochs are
**     involved:  the epoch of the elements and the epoch of
**     observation.
**
**     For comets, the epoch of perihelion fixes the position in the
**     orbit and in general a different epoch of osculation will be
**     chosen.  Thus, all three types of epoch are involved.
**
**     For the present function:
**
**     . The epoch of observation is the argument date.
**
**     . The epoch defining the position of the body is the argument
**       epoch.
**
**     . The osculating epoch is not used and is assumed to be close
**       enough to the epoch of observation to deliver adequate
**       accuracy.  If not, a preliminary call to slaPertel may be
**       used to update the element-set (and its associated osculating
**       epoch) by applying planetary perturbations.
**
**  6  Two important sources for orbital elements are Horizons, operated
**     by the Jet Propulsion Laboratory, Pasadena, and the Minor Planet
**     Center, operated by the Center for Astrophysics, Harvard.
**
**     The JPL Horizons elements (heliocentric, J2000 ecliptic and
**     equinox) correspond to SLALIB/C arguments as follows.
**
**       Major planets:
**
**         jform  = 1
**         epoch  = JDCT-2400000.5
**         orbinc = IN (in radians)
**         anode  = OM (in radians)
**         perih  = OM+W (in radians)
**         aorq   = A
**         e      = EC
**         aorl   = MA+OM+W (in radians)
**         dm     = N (in radians)
**
**         epoch of osculation = JDCT-2400000.5
**
**       Minor planets:
**
**         jform  = 2
**         epoch  = JDCT-2400000.5
**         orbinc = IN (in radians)
**         anode  = OM (in radians)
**         perih  = W (in radians)
**         aorq   = A
**         e      = EC
**         aorl   = MA (in radians)
**
**         epoch of osculation = JDCT-2400000.5
**
**       Comets:
**
**         jform  = 3
**         epoch  = Tp-2400000.5
**         orbinc = IN (in radians)
**         anode  = OM (in radians)
**         perih  = W (in radians)
**         aorq   = QR
**         e      = EC
**
**         epoch of osculation = JDCT-2400000.5
**
**     The MPC elements correspond to SLALIB/C arguments as follows.
**
**       Minor planets:
**
**         jform  = 2
**         epoch  = Epoch-2400000.5
**         orbinc = Incl. (in radians)
**         anode  = Node (in radians)
**         perih  = Perih. (in radians)
**         aorq   = a
**         e      = e
**         aorl   = M (in radians)
**
**         epoch of osculation = Epoch-2400000.5
**
**       Comets:
**
**         jform  = 3
**         epoch  = T-2400000.5
**         orbinc = Incl. (in radians)
**         anode  = Node. (in radians)
**         perih  = Perih. (in radians)
**         aorq   = q
**         e      = e
**
**         epoch of osculation = Epoch-2400000.5
**
**  Called: slaEl2ue, slaPlantu
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPlantu ( double date, double elong, double phi, double u[],
                 double *ra, double *dec, double *r, int *jstat)
/*
**  - - - - - - - - - -
**   s l a P l a n t u
**  - - - - - - - - - -
**
**  Topocentric apparent RA,Dec of a Solar-System object whose
**  heliocentric universal elements are known.
**
**  Given:
**     date    double     TT MJD of observation (JD - 2400000.5)
**     elong   double     observer's east longitude (radians)
**     phi     double     observer's geodetic latitude (radians)
**
**  Given and returned:
**     u       double[13] universal orbital elements
**
**                    [0] combined mass (M+m)
**                    [1] total energy of the orbit (alpha)
**                    [2] reference (osculating) epoch (t0)
**                  [3-5] position at reference epoch (r0)
**                  [6-8] velocity at reference epoch (v0)
**                    [9] heliocentric distance at reference epoch
**                   [10] r0.v0
**                   [11] date (t)
**                   [12] universal eccentric anomaly (psi) of date, approx
**
**  Returned:
**     ra,dec  double*    RA, Dec (topocentric apparent, radians)
**     r       double*    distance from observer (AU)
**     jstat   int*       status:  0 = OK
**                                -1 = radius vector zero
**                                -2 = failed to converge
**
**  Notes:
**
**  1  DATE is the instant for which the prediction is required.  It is
**     in the TT timescale (formerly Ephemeris Time, ET) and is a
**     Modified Julian Date (JD-2400000.5).
**
**  2  The longitude and latitude allow correction for geocentric
**     parallax.  This is usually a small effect, but can become
**     important for near-Earth asteroids.  Geocentric positions can be
**     generated by appropriate use of functions slaEpv (or slaEvp) and
**     slaUe2pv.
**
**  3  The "universal" elements are those which define the orbit for the
**     purposes of the method of universal variables (see reference 2).
**     They consist of the combined mass of the two bodies, an epoch,
**     and the position and velocity vectors (arbitrary reference frame)
**     at that epoch.  The parameter set used here includes also various
**     quantities that can, in fact, be derived from the other
**     information.  This approach is taken to avoiding unnecessary
**     computation and loss of accuracy.  The supplementary quantities
**     are (i) alpha, which is proportional to the total energy of the
**     orbit, (ii) the heliocentric distance at epoch, (iii) the
**     outwards component of the velocity at the given epoch, (iv) an
**     estimate of psi, the "universal eccentric anomaly" at a given
**     date and (v) that date.
**
**  4  The universal elements are with respect to the J2000 equator and
**     equinox.
**
**  Called: slaEpv, slaUe2pv, slaGmst, slaDt, slaEpj, slaPrenut,
**          slaDmxv, slaPvobs, slaDcc2s, slaDranrm
**
**     1  Sterne, Theodore E., "An Introduction to Celestial Mechanics",
**        Interscience Publishers Inc., 1960.  Section 6.7, p199.
**
**     2  Everhart, E. & Pitkin, E.T., Am.J.Phys. 51, 712, 1983.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPm ( double r0, double d0, double pr, double pd,
             double px, double rv, double ep0, double ep1,
             double *r1, double *d1 )
/*
**  - - - - - -
**   s l a P m
**  - - - - - -
**
**  Apply corrections for proper motion to a star RA,Dec.
**
**  (double precision)
**
**  References:
**     1984 Astronomical Almanac, pp B39-B41.
**     (also Lederle & Schwan, Astron. Astrophys. 134, 1-6, 1984)
**
**  Given:
**     r0,d0    double     RA,Dec at epoch ep0 (rad)
**     pr,pd    double     proper motions:  RA,Dec changes per year of epoch
**     px       double     parallax (arcsec)
**     rv       double     radial velocity (km/sec, +ve if receding)
**     ep0      double     start epoch in years (e.g Julian epoch)
**     ep1      double     end epoch in years (same system as ep0)
**
**  Returned:
**     *r1,*d1  double     RA,Dec at epoch ep1 (rad)
**
**  Notes:
**
**  1  The proper motions in RA are dRA/dt rather than cos(Dec)*dRA/dt,
**     and are in the same coordinate system as R0,D0.
**
**  2  If the available proper motions are pre-FK5 they will be per
**     tropical year rather than per Julian year, and so the epochs
**     must both be Besselian rather than Julian.  In such cases, a
**     scaling factor of 365.2422D0/365.25D0 should be applied to the
**     radial velocity before use.
**
**  Called:  slaDcs2c, slaDcc2s, slaDranrm
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   3 August 2004
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPncio ( double date, double rnpb[3][3] )
/*
**  - - - - - - - - -
**   s l a P n c i o
**  - - - - - - - - -
**
**  Form the CIO based precession-nutation matrix, with respect to the
**  geocentric celestial reference system.
**
**  Given:
**     date   double        TDB Modified Julian Date
**
**  Returned:
**     rnpb   double[3][3]  combined nutation x precession x bias matrix
**
**  Called:  slaPfw, slaNu, slaFw2xy, slaG2ixys, slaS
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT will do.
**
**  2)  The matrix is in the sense   V(CIRS) = RNPB * V(GCRS)
**
**  Last revision:   3 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPneqx ( double date, double rnpb[3][3] )
/*
**  - - - - - - - - -
**   s l a P n e q x
**  - - - - - - - - -
**
**  Form the classical precession-nutation matrix, with respect to the
**  geocentric celestial reference system.
**
**  Given:
**     date   double        TDB Modified Julian Date
**
**  Returned:
**     rnpb   double[3][3]  combined nutation x precession x bias matrix
**
**  Called:  slaPfw, slaNu, slaFw2m
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT will do.
**
**  2)  The matrix is in the sense   V(true) = RNPB * V(GCRS)
**
**  Last revision:   30 December 2005
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPolmo ( double elongm, double phim, double xp, double yp,
                double *elong, double *phi, double *daz )
/*
**  - - - - - - - - -
**   s l a P o l m o
**  - - - - - - - - -
**
**  Polar motion:  correct site longitude and latitude for polar
**  motion and calculate azimuth difference between celestial and
**  terrestrial poles.
**
**  Given:
**     elongm   double    mean longitude of the observer (radians, east +ve)
**     phim     double    mean geodetic latitude of the observer (radians)
**     xp       double    polar motion x-coordinate (radians)
**     yp       double    polar motion y-coordinate (radians)
**
**  Returned:
**     elong    double*   true longitude of the observer (radians, east +ve)
**     phi      double*   true geodetic latitude of the observer (radians)
**     daz      double*   azimuth correction (terrestrial-celestial, radians)
**
**  Notes:
**
**   1)  "Mean" longitude and latitude are the (fixed) values for the
**       site's location with respect to the IERS terrestrial reference
**       frame;  the latitude is geodetic.  TAKE CARE WITH THE LONGITUDE
**       SIGN CONVENTION.  The longitudes used by the present function
**       are east-positive, in accordance with geographical convention
**       (and right-handed).  In particular, note that the longitudes
**       Returned by the slaObs function are west-positive, following
**       astronomical usage, and must be reversed in sign before use in
**       the present function.
**
**   2)  xp and yp are the (changing) coordinates of the celestial
**       intermediate pole with respect to the IERS Reference Pole.
**       xp is positive along the meridian at longitude 0 degrees,
**       and yp is positive along the meridian at longitude
**       270 degrees (i.e. 90 degrees west).  Values for xp,yp can
**       be obtained from IERS circulars and equivalent publications;
**       the maximum amplitude observed so far is about 0.3 arcseconds.
**
**   3)  "True" longitude and latitude are the (moving) values for
**       the site's location with respect to the celestial intermediate
**       pole and the meridian which corresponds to the Greenwich
**       apparent sidereal time.  The true longitude and latitude
**       link the terrestrial coordinates with the standard celestial
**       models (for precession, nutation, sidereal time etc).
**
**   4)  The azimuths produced by slaAop and slaAopqk are with
**       respect to due north as defined by the celestial intermediate
**       pole, and can therefore be called "celestial azimuths".
**       However, a telescope fixed to the Earth measures azimuth
**       essentially with respect to due north as defined by the
**       IERS Reference Pole, and can therefore be called "terrestrial
**       azimuth".  Uncorrected, this would manifest itself as a
**       changing "azimuth zero-point error".  The value daz is the
**       correction to be added to a celestial azimuth to produce
**       a terrestrial azimuth.
**
**   5)  The present function is rigorous.  For most practical purposes,
**       the following simplified formulae provide an adequate
**       approximation:
**
**       elong = elongm+xp*cos(elongm)-yp*sin(elongm);
**       phi   = phim+(xp*sin(elongm)+yp*cos(elongm))*tan(phim);
**       daz   = -sqrt(xp*xp+yp*yp)*cos(elongm-atan2(xp,yp))/cos(phim);
**
**       An alternative formulation for daz is:
**
**       x = cos(elongm)*cos(phim);
**       y = sin(elongm)*cos(phim);
**       daz = atan2(-x*yp-y*xp,x*x+y*y);
**
**   Reference:  Seidelmann, P.K. (ed), 1992.  "Explanatory Supplement
**               to the Astronomical Almanac", ISBN 0-935702-68-7,
**               sections 3.27, 4.25, 4.52.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPomom ( double date, double xp, double yp, double rpom[3][3] )
/*
**  - - - - - - - - -
**   s l a P o m o m
**  - - - - - - - - -
**
**  Form the matrix of polar motion for a given date.
**
**  Given:
**     date     double        TDB Modified Julian Date (Note 1)
**     xp,yp    double        coordinates of the pole (radians, Note 2)
**
**  Returned:
**     rpom     double[3][3]  polar-motion matrix (Note 4)
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  The result is
**     extremely insensitive to the date, so TT or even UTC can be
**     used.
**
**  2) xp and yp are the "coordinates of the pole", in radians, which
**     position the Celestial Intermediate Pole in the International
**     Terrestrial Reference System (see IERS Conventions 2003).  In a
**     geocentric right-handed triad u,v,w, where the w-axis points at
**     the north geographic pole, the v-axis points towards the origin
**     of longitudes and the u-axis completes the system, xp = +u and
**     yp = -v.
**
**  3) The other angle needed is the quantity s', which positions the
**     terrestrial intermediate origin on the equator.  A standard model
**     is used.
**
**  4) The matrix operates in the sense v(TRS) = rpom * v(CIP), meaning
**     that it is the final rotation when computing the pointing
**     direction to a celestial source.
**
**  Called:  slaSp, slaDeuler
**
**  Reference:
**
**     McCarthy, D. D., Petit, G. (eds.) 2004, IERS Conventions (2003),
**     IERS Technical Note No. 32, BKG
**
**  Last revision:   8 January 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPrebn ( double bep0, double bep1, double rmatp[3][3] )
/*
**  - - - - - - - - -
**   s l a P r e b n
**  - - - - - - - - -
**
**  Generate the matrix of precession between two epochs,
**  using the old, pre-IAU1976, Bessel-Newcomb model, using
**  Kinoshita's formulation (double precision)
**
**  Given:
**     BEP0    double        beginning Besselian epoch
**     BEP1    double        ending Besselian epoch
**
**  Returned:
**     RMATP   double[3][3]  precession matrix
**
**  The matrix is in the sense   v(bep1)  =  rmatp * v(bep0)
**
**  Reference:
**     Kinoshita, H. (1975) 'Formulas for precession', SAO Special
**     Report No. 364, Smithsonian Institution Astrophysical
**     Observatory, Cambridge, Massachusetts.
**
**  Called:  slaDeuler
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   30 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPrec ( double ep0, double ep1, double rmatp[3][3] )
/*
**  - - - - - - - -
**   s l a P r e c
**  - - - - - - - -
**
**  Form the matrix of precession between two epochs (IAU 1976, FK5).
**
**  Given:
**     ep0    double         beginning epoch
**     ep1    double         ending epoch
**
**  Returned:
**     rmatp  double[3][3]   precession matrix
**
**  Notes:
**
**  1)  The epochs are TDB (loosely ET) Julian epochs.
**
**  2)  The matrix is in the sense   v(ep1)  =  rmatp * v(ep0) .
**
**  3)  Though the matrix method itself is rigorous, the precession
**      angles are expressed through canonical polynomials which are
**      valid only for a limited time span.  There are also known
**      errors in the IAU precession rate.  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.
**      The SLALIB function slaPrecl implements a more elaborate
**      model which is suitable for problems spanning several
**      thousand years.
**
**  References:
**     Lieske,J.H., 1979. Astron. Astrophys.,73,282.
**          equations (6) & (7), p283.
**     Kaplan,G.H., 1981. USNO circular no. 163, pa2.
**
**  Called:  slaDeuler
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPreces ( char sys[3], double ep0, double ep1,
                 double *ra, double *dc )
/*
**  - - - - - - - - - -
**   s l a P r e c e s
**  - - - - - - - - - -
**
**  Precession - either FK4 (Bessel-Newcomb, pre-IAU1976) or
**  FK5 (Fricke, post-IAU1976) as required.
**
**  Given:
**     sys        char[]     precession to be applied: "FK4" or "FK5"
**     ep0,ep1    double     starting and ending epoch
**     ra,dc      double     RA,Dec, mean equator & equinox of epoch ep0
**
**  Returned:
**     *ra,*dc    double     RA,Dec, mean equator & equinox of epoch ep1
**
**  Called:    slaDranrm, slaPrebn, slaPrec, slaDcs2c,
**             slaDmxv, slaDcc2s
**
**  Notes:
**
**  1)  The epochs are Besselian if sys='FK4' and Julian if 'FK5'.
**      For example, to precess coordinates in the old system from
**      equinox 1900.0 to 1950.0 the call would be:
**          slaPreces ( "FK4", 1900.0, 1950.0, &ra, &dc )
**
**  2)  This function will not correctly convert between the old and
**      the new systems - for example conversion from B1950 to J2000.
**      For these purposes see slaFk425, slaFk524, slaFk45z and
**      slaFk54z.
**
**  3)  If an invalid sys is supplied, values of -99.0,-99.0 will
**      be returned for both ra and dc.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPrecl ( double ep0, double ep1, double rmatp[3][3] )
/*
**  - - - - - - - - -
**   s l a P r e c l
**  - - - - - - - - -
**
**  Form the matrix of precession between two epochs, using the
**  model of Simon et al (1994), which is suitable for long
**  periods of time.
**
**  (double precision)
**
**  Given:
**     ep0    double         beginning epoch
**     ep1    double         ending epoch
**
**  Returned:
**     rmatp  double[3][3]   precession matrix
**
**  Notes:
**
**  1)  The epochs are TDB (loosely ET) Julian epochs.
**
**  2)  The matrix is in the sense   v(ep1)  =  rmatp * v(ep0) .
**
**  3)  The absolute accuracy of the model is limited by the
**      uncertainty in the general precession, about 0.3 arcsec per
**      1000 years.  The remainder of the formulation provides a
**      precision of 1 mas over the interval from 1000AD to 3000AD,
**      0.1 arcsec from 1000BC to 5000AD and 1 arcsec from
**      4000BC to 8000AD.
**
**  Reference:
**     Simon, J.L., et al., 1994. Astron.Astrophys., 282, 663-683.
**
**  Called:  slaDeuler
**
**  Defined in slamac.h:  DAS2R
**
**  Last revision:   23 August 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPrenut ( double epoch, double date, double rmatpn[3][3] )
/*
**  - - - - - - - - - -
**   s l a P r e n u t
**  - - - - - - - - - -
**
**  Form the matrix of precession and nutation (SF2001)
**
**  (double precision)
**
**  Given:
**     epoch   double         Julian epoch for mean coordinates
**     date    double         Modified Julian Date (JD-2400000.5)
**                            for true coordinates
**
**
**  Returned:
**     rmatpn  double[3][3]   combined precession/nutation matrix
**
**  Called:  slaPrec, slaEpj, slaNut, slaDmxm
**
**  Notes:
**
**  1)  The epoch and date are TDB (loosely ET).  TT (or even UTC) will
**      do.
**
**  2)  The matrix is in the sense   v(true)  =  rmatpn * v(mean) .
**
**  Last revision:   3 December 2005
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPv2el ( double pv[], double date, double pmass, int jformr,
                int *jform, double *epoch, double *orbinc,
                double *anode, double *perih, double *aorq, double *e,
                double *aorl, double *dm, int *jstat )
/*
**  - - - - - - - - -
**   s l a P v 2 e l
**  - - - - - - - - -
**
**  Heliocentric osculating elements obtained from instantaneous position
**  and velocity.
**
**  Given:
**     pv      double[6]  heliocentric x,y,z,xdot,ydot,zdot of date,
**                         J2000 equatorial triad (AU,AU/s; Note 1)
**     date    double     date (TT Modified Julian Date = JD-2400000.5)
**     pmass   double     mass of the planet (Sun=1; Note 2)
**     jformr  int        requested element set (1-3; Note 3)
**
**  Returned:
**     jform   double*    element set actually returned (1-3; Note 4)
**     epoch   double*    epoch of elements (TT MJD)
**     orbinc  double*    inclination (radians)
**     anode   double*    longitude of the ascending node (radians)
**     perih   double*    longitude or argument of perihelion (radians)
**     aorq    double*    mean distance or perihelion distance (AU)
**     e       double*    eccentricity
**     aorl    double*    mean anomaly or longitude (radians, jform=1,2 only)
**     dm      double*    daily motion (radians, jform=1 only)
**     jstat   int*       status:  0 = OK
**                                -1 = illegal pmass
**                                -2 = illegal jformr
**                                -3 = position/velocity out of range
**
**  Notes
**
**  1  The pv 6-vector is with respect to the mean equator and equinox of
**     epoch J2000.  The orbital elements produced are with respect to
**     the J2000 ecliptic and mean equinox.
**
**  2  The mass, pmass, is important only for the larger planets.  For
**     most purposes (e.g. asteroids) use 0.0.  Values less than zero
**     are illegal.
**
**  3  Three different element-format options are supported:
**
**     Option jformr=1, suitable for the major planets:
**
**     epoch  = epoch of elements (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = longitude of perihelion, curly pi (radians)
**     aorq   = mean distance, a (AU)
**     e      = eccentricity, e
**     aorl   = mean longitude L (radians)
**     dm     = daily motion (radians)
**
**     Option jformr=2, suitable for minor planets:
**
**     epoch  = epoch of elements (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = argument of perihelion, little omega (radians)
**     aorq   = mean distance, a (AU)
**     e      = eccentricity, e
**     aorl   = mean anomaly M (radians)
**
**     Option jformr=3, suitable for comets:
**
**     epoch  = epoch of perihelion (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = argument of perihelion, little omega (radians)
**     aorq   = perihelion distance, q (AU)
**     e      = eccentricity, e
**
**  4  It may not be possible to generate elements in the form
**     requested through jformr.  The caller is notified of the form
**     of elements actually returned by means of the jform argument:
**
**      jformr   jform     meaning
**
**        1        1       OK - elements are in the requested format
**        1        2       never happens
**        1        3       orbit not elliptical
**
**        2        1       never happens
**        2        2       OK - elements are in the requested format
**        2        3       orbit not elliptical
**
**        3        1       never happens
**        3        2       never happens
**        3        3       OK - elements are in the requested format
**
**  5  The arguments returned for each value of jform (cf Note 5: jform
**     may not be the same as jformr) are as follows:
**
**         jform         1              2              3
**         epoch         t0             t0             T
**         orbinc        i              i              i
**         anode         Omega          Omega          Omega
**         perih         curly pi       omega          omega
**         aorq          a              a              q
**         e             e              e              e
**         aorl          L              M              -
**         dm            n              -              -
**
**     where:
**
**         t0           is the epoch of the elements (MJD, TT)
**         T              "    epoch of perihelion (MJD, TT)
**         i              "    inclination (radians)
**         Omega          "    longitude of the ascending node (radians)
**         curly pi       "    longitude of perihelion (radians)
**         omega          "    argument of perihelion (radians)
**         a              "    mean distance (AU)
**         q              "    perihelion distance (AU)
**         e              "    eccentricity
**         L              "    longitude (radians, 0-2pi)
**         M              "    mean anomaly (radians, 0-2pi)
**         n              "    daily motion (radians)
**         -             means no value is set
**
**  6  At very small inclinations, the longitude of the ascending node
**     anode becomes indeterminate and under some circumstances may be
**     set arbitrarily to zero.  Similarly, if the orbit is close to
**     circular, the true anomaly becomes indeterminate and under some
**     circumstances may be set arbitrarily to zero.  In such cases,
**     the other elements are automatically adjusted to compensate,
**     and so the elements remain a valid description of the orbit.
**
**  7  The osculating epoch for the returned elements is the argument
**     "date".
**
**  Reference:  Sterne, Theodore E., "An Introduction to Celestial
**              Mechanics", Interscience Publishers, 1960
**
**  Called:  slaDranrm
**
**  Last revision:   7 September 2005
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPv2ue ( double pv[], double date, double pmass,
                double u[], int *jstat )
/*
**  - - - - - - - - -
**   s l a P v 2 u e
**  - - - - - - - - -
**
**  Construct a universal element set based on an instantaneous position
**  and velocity.
**
**  Given:
**     pv      double[6]  heliocentric x,y,z,xdot,ydot,zdot of date,
**                        (au,au/s; Note 1)
**     date    double     date (TT Modified Julian Date = JD-2400000.5)
**     pmass   double     mass of the planet (Sun=1; Note 2)
**
**  Returned:
**
**     u       double[13] universal orbital elements (Note 3)
**
**                    [0] combined mass (M+m)
**                    [1] total energy of the orbit (alpha)
**                    [2] reference (osculating) epoch (t0)
**                  [3-5] position at reference epoch (r0)
**                  [6-8] velocity at reference epoch (v0)
**                    [9] heliocentric distance at reference epoch
**                   [10] r0.v0
**                   [11] date (t)
**                   [12] universal eccentric anomaly (psi) of date
**
**     jstat   int*       status:  0 = OK
**                                -1 = illegal pmass
**                                -2 = too close to Sun
**                                -3 = too slow
**
**  Notes
**
**  1  The pv 6-vector can be with respect to any chosen inertial frame,
**     and the resulting universal-element set will be with respect to
**     the same frame.  A common choice will be mean equator and ecliptic
**     of epoch J2000.
**
**  2  The mass, pmass, is important only for the larger planets.  For
**     most purposes (e.g. asteroids) use 0.0.  Values less than zero
**     are illegal.
**
**  3  The "universal" elements are those which define the orbit for the
**     purposes of the method of universal variables (see reference).
**     They consist of the combined mass of the two bodies, an epoch,
**     and the position and velocity vectors (arbitrary reference frame)
**     at that epoch.  The parameter set used here includes also various
**     quantities that can, in fact, be derived from the other
**     information.  This approach is taken to avoiding unnecessary
**     computation and loss of accuracy.  The supplementary quantities
**     are (i) alpha, which is proportional to the total energy of the
**     orbit, (ii) the heliocentric distance at epoch, (iii) the
**     outwards component of the velocity at the given epoch, (iv) an
**     estimate of psi, the "universal eccentric anomaly" at a given
**     date and (v) that date.
**
**  Reference:  Everhart, E. & Pitkin, E.T., Am.J.Phys. 51, 712, 1983.
**
**  Last revision:   17 March 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPvobs ( double p, double h, double stl, double pv[6] )
/*
**  - - - - - - - - -
**   s l a P v o b s
**  - - - - - - - - -
**
**  Position and velocity of an observing station.
**
**  (double precision)
**
**  Given:
**     p     double     latitude (geodetic, radians)
**     h     double     height above reference spheroid (geodetic, metres)
**     stl   double     local apparent sidereal time (radians)
**
**  Returned:
**     pv    double[6]  position/velocity 6-vector (au, au/s, true
**                                         equator and equinox of date)
**
**  IAU 1976 constants are used.
**
**  Called:  slaGeoc
**
**  Last revision:   14 November 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaPxy ( int np, double xye[][2], double xym[][2],
              double coeffs[6], double xyp[][2],
              double *xrms, double *yrms, double *rrms )
/*
**  - - - - - - -
**   s l a P x y
**  - - - - - - -
**
**  Given arrays of "expected" and "measured" [x,y] coordinates, and a
**  linear model relating them (as produced by slaFitxy), compute
**  the array of "predicted" coordinates and the rms residuals.
**
**  Given:
**     np      int            number of samples
**     xye     double[np]     expected [x,y] for each sample
**     xym     double[np]     measured [x,y] for each sample
**     coeffs  double[6]      coefficients of model (see below)
**
**  Returned:
**     xyp     double[np]     predicted [x,y] for each sample
**     *xrms   double         RMS in x
**     *yrms   double         RMS in y
**     *rrms   double         total RMS (vector sum of xrms and yrms)
**
**  The model is supplied in the array coeffs.  Naming the
**  elements of coeff as follows:
**
**     coeffs[0] = a
**     coeffs[1] = b
**     coeffs[2] = c
**     coeffs[3] = d
**     coeffs[4] = e
**     coeffs[5] = f
**
**  The model is applied thus:
**
**     xp = a + b*xm + c*ym
**     yp = d + e*xm + f*ym
**
**  The residuals are (xp-xe) and (yp-ye).
**
**  If np is less than or equal to zero, no coordinates are
**  transformed, and the rms residuals are all zero.
**
**  See also slaFitxy, slaInvf, slaXy2xy, slaDcmpf
**
**  Called:  slaXy2xy
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaRange ( float angle )
/*
**  - - - - - - - - -
**   s l a R a n g e
**  - - - - - - - - -
**
**  Normalize angle into range +/- pi.
**
**  (single precision)
**
**  Given:
**     angle     float      the angle in radians
**
**  The result is angle expressed in the +/- pi (single precision).
**
**  Last revision:   31 October 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaRanorm ( float angle )
/*
**  - - - - - - - - - -
**   s l a R a n o r m
**  - - - - - - - - - -
**
**  Normalize angle into range 0-2 pi.
**
**  (single precision)
**
**  Given:
**     angle     double      the angle in radians
**
**  The result is angle expressed in the range 0-2 pi (single
**  precision).
**
**  Last revision:   15 July 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaRcc ( double tdb, double ut1, double wl, double u, double v )
/*
**  - - - - - - -
**   s l a R c c
**  - - - - - - -
**
**  Relativistic clock correction:  the difference between proper time at
**  a point on the surface of the Earth and coordinate time in the Solar
**  System barycentric space-time frame of reference.
**
**  The proper time is terrestrial time, TT;  the coordinate time is an
**  implementation of barycentric dynamical time, TDB.
**
**  Given:
**    TDB   double   TDB (MJD: JD-2400000.5)
**    UT1   double   universal time (fraction of one day)
**    WL    double   clock longitude (radians west)
**    U     double   clock distance from Earth spin axis (km)
**    V     double   clock distance north of Earth equatorial plane (km)
**
**  Returned:
**    The clock correction, TDB-TT, in seconds:
**
**    .  TDB is coordinate time in the solar system barycentre frame
**       of reference, in units chosen to eliminate the scale difference
**       with respect to terrestrial time.
**
**    .  TT is the proper time for clocks at mean sea level on the Earth.
**
**  Notes:
**
**  1  The argument TDB is, strictly, the barycentric coordinate time;
**     however, the terrestrial time TT can in practice be used without
**     any significant loss of accuracy.
**
**  2  The result returned by slaRcc comprises a main (annual) sinusoidal
**     term of amplitude approximately 0.00166 seconds, plus planetary
**     and lunar terms up to about 20 microseconds, and diurnal terms up
**     to 2 microseconds.  The variation arises from the transverse Doppler
**     effect and the gravitational red-shift as the observer varies in
**     speed and moves through different gravitational potentials.
**
**  3  The geocentric model is that of Fairhead & Bretagnon (1990), in its
**     full form.  It was supplied by Fairhead (private communication) as
**     a FORTRAN subroutine.  The original Fairhead routine used explicit
**     formulae, in such large numbers that problems were experienced with
**     certain compilers (Microsoft Fortran on PC aborted with stack
**     overflow, Convex compiled successfully but extremely slowly).  The
**     present implementation is a complete recoding in C, with the
**     original Fairhead coefficients held in a table.  To optimize
**     arithmetic precision, the terms are accumulated in reverse order,
**     smallest first.  The numerical results from this C version agree
**     with those from the original Fairhead Fortran code to better than
**     10^-15 seconds.
**
**  4  The topocentric part of the model is from Moyer (1981) and
**     Murray (1983).  It is an approximation to the expression
**     ( v / c ) . ( r / c ), where v is the barycentric velocity of
**     the Earth, r is the geocentric position of the observer and
**     c is the speed of light.
**
**  5  During the interval 1950-2050, the absolute accuracy is better
**     than +/- 3 nanoseconds relative to direct numerical integrations
**     using the JPL DE200/LE200 solar system ephemeris.
**
**  6  The IAU definition of TDB was that it must differ from TT only
**     by periodic terms.  Though practical, this is an imprecise
**     definition which ignores the existence of very long-period and
**     secular effects in the dynamics of the solar system.  As a
**     consequence, different implementations of TDB will, in general,
**     differ in zero-point and will drift linearly relative to one other.
**
**  7  TDB was, in principle, superseded by new coordinate timescales
**     which the IAU introduced in 1991:  geocentric coordinate time,
**     TCG, and barycentric coordinate time, TCB.  However, slaRcc
**     can be used to implement the periodic part of TCB-TCG.
**
**  References:
**
**  1  Fairhead, L., & Bretagnon, P., Astron.Astrophys., 229, 240-247
**     (1990).
**
**  2  Moyer, T.D., Cel.Mech., 23, 33 (1981).
**
**  3  Murray, C.A., Vectorial Astrometry, Adam Hilger (1983).
**
**  4  Seidelmann, P.K. et al, Explanatory Supplement to the
**     Astronomical Almanac, Chapter 2, University Science Books (1992).
**
**  5  Simon J.L., Bretagnon P., Chapront J., Chapront-Touze M.,
**     Francou G. & Laskar J., Astron.Astrophys., 282, 663-683 (1994).
**
**  Defined in slamac.h:  D2PI, DD2R, dmod
**
**  Last revision:   8 May 2000
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaRdplan ( double date, int np, double elong, double phi,
                 double *ra, double *dec, double *diam )
/*
**  - - - - - - - - - -
**   s l a R d p l a n
**  - - - - - - - - - -
**
**  Approximate topocentric apparent RA,Dec of a planet (also Sun,
**  Moon and Pluto), and its angular diameter.
**
**  Given:
**     date        double     MJD of observation (JD - 2400000.5)
**     np          int        body: 1 = Mercury
**                                  2 = Venus
**                                  3 = Moon
**                                  4 = Mars
**                                  5 = Jupiter
**                                  6 = Saturn
**                                  7 = Uranus
**                                  8 = Neptune
**                                  9 = Pluto
**                               else = Sun
**     elong,phi   double     observer's east longitude and geodetic
**                                                  latitude (radians)
**
**  Returned:
**     ra,dec      double     RA, Dec (topocentric apparent, radians)
**     diam        double     angular diameter (equatorial, radians)
**
**  Notes:
**
**  1  The date is in a dynamical timescale (TDB, formerly ET) and is
**     in the form of a Modified Julian Date (JD-2400000.5).  For all
**     practical purposes, TT can be used instead of TDB, and for many
**     applications UT will do (except for the Moon).
**
**  2  The longitude and latitude allow correction for geocentric
**     parallax.  This is a major effect for the Moon, but in the
**     context of the limited accuracy of the present function its
**     effect on planetary positions is small (negligible for the
**     outer planets).  Geocentric positions can be generated by
**     appropriate use of the functions slaDmoon and slaPlanet.
**
**  3  The direction accuracy (arcsec, 1000-3000AD) is of order:
**
**            Sun              5
**            Mercury          2
**            Venus           10
**            Moon            30
**            Mars            50
**            Jupiter         90
**            Saturn          90
**            Uranus          90
**            Neptune         10
**            Pluto            1   (1885-2099AD only)
**
**     The angular diameter accuracy is about 0.4% for the Moon,
**     and 0.01% or better for the other bodies.
**
**  Called: slaGmst, slaDt, slaEpj, slaDmoon, slaPvobs, slaPrenut,
**          slaPlanet, slaDmxv, slaDcc2s, slaDranrm
**
**  Last revision:   22 November 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaRefco ( double hm, double tdk, double pmb, double rh,
                double wl, double phi, double tlr, double eps,
                double *refa, double *refb )
/*
**  - - - - - - - - -
**   s l a R e f c o
**  - - - - - - - - -
**
**  Determine constants A and B in atmospheric refraction model
**  dz = A tan z + B tan^3 z.
**
**  z is the "observed" zenith distance (i.e. affected by
**  refraction) and dz is what to add to z to give the "topocentric"
**  (i.e. in vacuo) zenith distance.
**
**  Given:
**    hm    double    height of the observer above sea level (metre)
**    tdk   double    ambient temperature at the observer (K)
**    pmb   double    pressure at the observer (millibar)
**    rh    double    relative humidity at the observer (range 0-1)
**    wl    double    effective wavelength of the source (micrometre)
**    phi   double    latitude of the observer (radian, astronomical)
**    tlr   double    temperature lapse rate in the troposphere (K/metre)
**    eps   double    precision required to terminate iteration (radian)
**
**  Returned:
**    *refa double    tan z coefficient (radian)
**    *refb double    tan^3 z coefficient (radian)
**
**  Called:  slaRefro
**
**  Notes:
**
**  1  Typical values for the tlr and eps arguments might be 0.0065 and
**     1e-10 respectively.
**
**  2  The radio refraction is chosen by specifying wl > 100 micrometres.
**
**  3  The function is a slower but more accurate alternative to the
**     slaRefcoq function.  The constants it produces give perfect
**     agreement with slaRefro at zenith distances arctan(1) (45 deg)
**     and arctan(4) (about 76 deg).  It achieves 0.5 arcsec accuracy
**     for ZD < 80 deg, 0.01 arcsec accuracy for ZD < 60 deg, and
**     0.001 arcsec accuracy for ZD < 45 deg.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaRefcoq ( double tdk, double pmb, double rh, double wl,
                 double *refa, double *refb )
/*
**  - - - - - - - - - -
**   s l a R e f c o q
**  - - - - - - - - - -
**
**  Determine the constants A and B in the atmospheric refraction
**  model dZ = A tan Z + B tan^3 Z.  This is a fast alternative
**  to the slaRefco function - see notes.
**
**  Z is the "observed" zenith distance (i.e. affected by refraction)
**  and dZ is what to add to Z to give the "topocentric" (i.e. in vacuo)
**  zenith distance.
**
**  Given:
**    tdk    double    ambient temperature at the observer (K)
**    pmb    double    pressure at the observer (millibar)
**    rh     double    relative humidity at the observer (range 0-1)
**    wl     double    effective wavelength of the source (micrometre)
**
**  Returned:
**    refa   double*   tan Z coefficient (radian)
**    refb   double*   tan^3 Z coefficient (radian)
**
**  The radio refraction is chosen by specifying WL > 100 micrometres.
**
**  Notes:
**
**  1  The model is an approximation, for moderate zenith distances,
**     to the predictions of the slaRefro function.  The approximation
**     is maintained across a range of conditions, and applies to
**     both optical/IR and radio.
**
**  2  The algorithm is a fast alternative to the slaRefco function.
**     The latter calls the slaRefro function itself:  this involves
**     integrations through a model atmosphere, and is costly in
**     processor time.  However, the model which is produced is precisely
**     correct for two zenith distance (45 degrees and about 76 degrees)
**     and at other zenith distances is limited in accuracy only by the
**     A tan Z + B tan^3 Z formulation itself.  The present function
**     is not as accurate, though it satisfies most practical
**     requirements.
**
**  3  The model omits the effects of (i) height above sea level (apart
**     from the reduced pressure itself), (ii) latitude (i.e. the
**     flattening of the Earth) and (iii) variations in tropospheric
**     lapse rate.
**
**     The model was tested using the following range of conditions:
**
**       lapse rates 0.0055, 0.0065, 0.0075 deg/metre
**       latitudes 0, 25, 50, 75 degrees
**       heights 0, 2500, 5000 metres ASL
**       pressures mean for height -10% to +5% in steps of 5%
**       temperatures -10 deg to +20 deg with respect to 280 deg at SL
**       relative humidity 0, 0.5, 1
**       wavelengths 0.4, 0.6, ... 2 micron, + radio
**       zenith distances 15, 45, 75 degrees
**
**     The accuracy with respect to direct use of the slaRefro function
**     was as follows:
**
**                            worst         RMS
**
**       optical/IR           62 mas       8 mas
**       radio               319 mas      49 mas
**
**     For this particular set of conditions:
**
**       lapse rate 0.0065 K/metre
**       latitude 50 degrees
**       sea level
**       pressure 1005 mb
**       temperature 280.15 K
**       humidity 80%
**       wavelength 5740 Angstroms
**
**     the results were as follows:
**
**       ZD        slaRefro    slaRefcoq   Saastamoinen
**
**       10         10.27        10.27        10.27
**       20         21.19        21.20        21.19
**       30         33.61        33.61        33.60
**       40         48.82        48.83        48.81
**       45         58.16        58.18        58.16
**       50         69.28        69.30        69.27
**       55         82.97        82.99        82.95
**       60        100.51       100.54       100.50
**       65        124.23       124.26       124.20
**       70        158.63       158.68       158.61
**       72        177.32       177.37       177.31
**       74        200.35       200.38       200.32
**       76        229.45       229.43       229.42
**       78        267.44       267.29       267.41
**       80        319.13       318.55       319.10
**
**      deg        arcsec       arcsec       arcsec
**
**     The values for Saastamoinen's formula (which includes terms
**     up to tan^5) are taken from Hohenkerk and Sinclair (1985).
**
**     The results from the much slower but more accurate slaRefco
**     function have not been included in the tabulation as they are
**     identical to those in the slaRefro column to the 0.01 arcsec
**     resolution used.
**
**  4  Outlandish input parameters are silently limited to mathematically
**     safe values.  Zero pressure is permissible, and causes zeroes to
**     be returned.
**
**  5  The algorithm draws on several sources, as follows:
**
**     a) The formula for the saturation vapour pressure of water as
**        a function of temperature and temperature is taken from
**        expressions A4.5-A4.7 of Gill (1982).
**
**     b) The formula for the water vapour pressure, given the
**        saturation pressure and the relative humidity, is from
**        Crane (1976), expression 2.5.5.
**
**     c) The refractivity of air is a function of temperature,
**        total pressure, water-vapour pressure and, in the case
**        of optical/IR but not radio, wavelength.  The formulae
**        for the two cases are developed from Hohenkerk & Sinclair
**        (1985) and Rueger (2002).
**
**     The above three items are as used in the slaRefro function.
**
**     d) The formula for beta, the ratio of the scale height of the
**        atmosphere to the geocentric distance of the observer, is
**        an adaption of expression 9 from Stone (1996).  The
**        adaptations, arrived at empirically, consist of (i) a
**        small adjustment to the coefficient and (ii) a humidity
**        term for the radio case only.
**
**     e) The formulae for the refraction constants as a function of
**        n-1 and beta are from Green (1987), expression 4.31.
**
**  References:
**
**     Crane, R.K., Meeks, M.L. (ed), "Refraction Effects in the Neutral
**     Atmosphere", Methods of Experimental Physics: Astrophysics 12B,
**     Academic Press, 1976.
**
**     Gill, Adrian E., "Atmosphere-Ocean Dynamics", Academic Press, 1982.
**
**     Green, R.M., "Spherical Astronomy", Cambridge University Press, 1987.
**
**     Hohenkerk, C.Y., & Sinclair, A.T., NAO Technical Note No. 63, 1985.
**
**     Rueger, J.M., "Refractive Index Formulae for Electronic Distance
**     Measurement with Radio and Millimetre Waves", in Unisurv Report
**     S-68, School of Surveying and Spatial Information Systems,
**     University of New South Wales, Sydney, Australia, 2002.
**
**     Stone, Ronald C., P.A.S.P. 108 1051-1058, 1996.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaRefro ( double zobs, double hm, double tdk, double pmb,
                double rh, double wl, double phi, double tlr,
                double eps, double *ref )
/*
**  - - - - - - - - -
**   s l a R e f r o
**  - - - - - - - - -
**
**  Atmospheric refraction for radio and optical/IR wavelengths.
**
**  Given:
**    zobs    double  observed zenith distance of the source (radian)
**    hm      double  height of the observer above sea level (metre)
**    tdk     double  ambient temperature at the observer (K)
**    pmb     double  pressure at the observer (millibar)
**    rh      double  relative humidity at the observer (range 0-1)
**    wl      double  effective wavelength of the source (micrometre)
**    phi     double  latitude of the observer (radian, astronomical)
**    tlr     double  tropospheric lapse rate (K/metre)
**    eps     double  precision required to terminate iteration (radian)
**
**  Returned:
**    ref     double  refraction: in vacuo ZD minus observed ZD (radian)
**
**  Notes:
**
**  1  A suggested value for the tlr argument is 0.0065.  The
**     refraction is significantly affected by tlr, and if studies
**     of the local atmosphere have been carried out a better tlr
**     value may be available.  The sign of the supplied TLR value
**     is ignored.
**
**  2  A suggested value for the eps argument is 1e-8.  The result is
**     usually at least two orders of magnitude more computationally
**     precise than the supplied eps value.
**
**  3  The function computes the refraction for zenith distances up
**     to and a little beyond 90 deg using the method of Hohenkerk
**     and Sinclair (NAO Technical Notes 59 and 63, subsequently adopted
**     in the Explanatory Supplement, 1992 edition - see section 3.281).
**
**  4  The C code is an adaptation of the Fortran optical/IR refraction
**     subroutine AREF of C.Hohenkerk (HMNAO, September 1984), with
**     extensions to support the radio case.  The following modifications
**     to the original HMNAO optical/IR refraction algorithm have been made:
**
**     .  The angle arguments have been changed to radians.
**
**     .  Any value of zobs is allowed (see note 6, below).
**
**     .  Other argument values have been limited to safe values.
**
**     .  Murray's values for the gas constants have been used
**        (Vectorial Astrometry, Adam Hilger, 1983).
**
**     .  The numerical integration phase has been rearranged for
**        extra clarity.
**
**     .  A better model for Ps(T) has been adopted (taken from
**        Gill, Atmosphere-Ocean Dynamics, Academic Press, 1982).
**
**     .  More accurate expressions for Pwo have been adopted
**        (again from Gill 1982).
**
**     .  The formula for the water vapour pressure, given the
**        saturation pressure and the relative humidity, is from
**        Crane (1976), expression 2.5.5.
**
**     .  Provision for radio wavelengths has been added using
**        expressions devised by A.T.Sinclair, RGO (private
**        communication 1989).  The refractivity model currently
**        used is from J.M.Rueger, "Refractive Index Formulae for
**        Electronic Distance Measurement with Radio and Millimetre
**        Waves", in Unisurv Report S-68 (2002), School of Surveying
**        and Spatial Information Systems, University of New South
**        Wales, Sydney, Australia.
**
**     .  The optical refractivity for dry air is from Resolution 3 of
**        the International Association of Geodesy adopted at the XXIIth
**        General Assembly in Birmingham, UK, 1999.
**
**     .  Various small changes have been made to gain speed.
**
**  5  The radio refraction is chosen by specifying wl > 100 micrometres.
**     Because the algorithm takes no account of the ionosphere, the
**     accuracy deteriorates at low frequencies, below about 30 MHz.
**
**  6  Before use, the value of zobs is expressed in the range +/- pi.
**     If this ranged zobs is -ve, the result ref is computed from its
**     absolute value before being made -ve to match.  In addition, if
**     it has an absolute value greater than 93 deg, a fixed ref value
**     equal to the result for zobs = 93 deg is returned, appropriately
**     signed.
**
**  7  As in the original Hohenkerk and Sinclair algorithm, fixed
**     values of the water vapour polytrope exponent, the height of the
**     tropopause, and the height at which refraction is negligible are
**     used.
**
**  8  The radio refraction has been tested against work done by
**     Iain Coulson, JACH, (private communication 1995) for the
**     James Clerk Maxwell Telescope, Mauna Kea.  For typical conditions,
**     agreement at the 0.1 arcsec level is achieved for moderate ZD,
**     worsening to perhaps 0.5-1.0 arcsec at ZD 80 deg.  At hot and
**     humid sea-level sites the accuracy will not be as good.
**
**  9  It should be noted that the relative humidity rh is formally
**     defined in terms of "mixing ratio" rather than pressures or
**     densities as is often stated.  It is the mass of water per unit
**     mass of dry air divided by that for saturated air at the same
**     temperature and pressure (see Gill 1982).
**
**  10 The algorithm is designed for observers in the troposphere.  The
**     supplied temperature, pressure and lapse rate are assumed to be
**     for a point in the troposphere and are used to define a model
**     atmosphere with the tropopause at 11km altitude and a constant
**     temperature above that.  However, in practice, the refraction
**     values returned for stratospheric observers, at altitudes up to
**     25km, are quite usable.
**
**  Called:  slaDrange, atmt, atms
**
**  Defined in slamac.h:  TRUE, FALSE
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaRefv ( double vu[3], double refa, double refb, double vr[3] )
/*
**  - - - - - - - -
**   s l a R e f v
**  - - - - - - - -
**
**  Adjust an unrefracted Cartesian vector to include the effect of
**  atmospheric refraction, using the simple A tan z + B tan^3 z
**  model.
**
**  Given:
**    vu    double    unrefracted position of the source (az/el 3-vector)
**    refa  double    A: tan z coefficient (radian)
**    refb  double    B: tan^3 z coefficient (radian)
**
**  Returned:
**    *vr   double    refracted position of the source (az/el 3-vector)
**
**  Notes:
**
**  1  This function applies the adjustment for refraction in the
**     opposite sense to the usual one - it takes an unrefracted
**     (in vacuo) position and produces an observed (refracted)
**     position, whereas the A tan Z + B tan^3 Z model strictly
**     applies to the case where an observed position is to have the
**     refraction removed.  The unrefracted to refracted case is
**     harder, and requires an inverted form of the text-book
**     refraction models;  the algorithm used here is equivalent to
**     one iteration of the Newton-Raphson method applied to the above
**     formula.
**
**  2  Though optimized for speed rather than precision, the present
**     function achieves consistency with the refracted-to-unrefracted
**     A tan Z + B tan^3 Z model at better than 1 microarcsecond within
**     30 degrees of the zenith and remains within 1 milliarcsecond to
**     beyond ZD 70 degrees.  The inherent accuracy of the model is, of
**     course, far worse than this - see the documentation for slaRefco
**     for more information.
**
**  3  At low elevations (below about 3 degrees) the refraction
**     correction is held back to prevent arithmetic problems and
**     wildly wrong results.  For optical/IR wavelengths, over a wide
**     range of observer heights and corresponding temperatures and
**     pressures, the following levels of accuracy (arcsec, worst case)
**     are achieved, relative to numerical integration through a model
**     atmosphere:
**
**              ZD    error
**
**              80      0.7
**              81      1.3
**              82      2.5
**              83      5
**              84     10
**              85     20
**              86     55
**              87    160
**              88    360
**              89    640
**              90   1100
**              91   1700         } relevant only to
**              92   2600         } high-elevation sites
**
**     The results for radio are slightly worse over most of the range,
**     becoming significantly worse below ZD=88 and unusable beyond
**     ZD=90.
**
**  4  See also the function slaRefz, which performs the adjustment to
**     the zenith distance rather than in Cartesian Az/El coordinates.
**     The present function is faster than slaRefz and, except very low
**     down, is equally accurate for all practical purposes.  However,
**     beyond about ZD 84 degrees slaRefz should be used, and for the
**     utmost accuracy iterative use of slaRefro should be considered.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaRefz ( double zu, double refa, double refb, double *zr )
/*
**  - - - - - - - -
**   s l a R e f z
**  - - - - - - - -
**
**  Adjust an unrefracted zenith distance to include the effect of
**  atmospheric refraction, using the simple A tan z + B tan^3 z
**  model.
**
**  Given:
**    zu    double    unrefracted zenith distance of the source (radian)
**    refa  double    A: tan z coefficient (radian)
**    refb  double    B: tan^3 z coefficient (radian)
**
**  Returned:
**    *zr   double    refracted zenith distance (radian)
**
**  Notes:
**
**  1  This function applies the adjustment for refraction in the
**     opposite sense to the usual one - it takes an unrefracted
**     (in vacuo) position and produces an observed (refracted)
**     position, whereas the A tan Z + B tan^3 Z model strictly
**     applies to the case where an observed position is to have the
**     refraction removed.  The unrefracted to refracted case is
**     harder, and requires an inverted form of the text-book
**     refraction models;  the formula used here is based on the
**     Newton-Raphson method.  For the utmost numerical consistency
**     with the refracted to unrefracted model, two iterations are
**     carried out, achieving agreement at the 1D-11 arcseconds level
**     for a ZD of 80 degrees.  The inherent accuracy of the model
**     is, of course, far worse than this - see the documentation for
**     slaRefco for more information.
**
**  2  At ZD 83 degrees, the rapidly-worsening A tan Z + B tan^3 Z
**     model is abandoned and an empirical formula takes over.  For
**     optical/IR wavelengths, over a wide range of observer heights and
**     corresponding temperatures and pressures, the following levels of
**     accuracy (arcsec, worst case) are achieved, relative to numerical
**     integration through a model atmosphere:
**
**              zr    error
**
**              80      0.7
**              81      1.3
**              82      2.4
**              83      4.7
**              84      6.2
**              85      6.4
**              86      8
**              87     10
**              88     15
**              89     30
**              90     60
**              91    150         } relevant only to
**              92    400         } high-elevation sites
**
**     For radio wavelengths the errors are typically 50% larger than
**     the optical figures and by ZD 85 deg are twice as bad, worsening
**     rapidly below that.  To maintain 1 arcsec accuracy down to ZD=85
**     at the Green Bank site, Condon (2004) has suggested amplifying
**     the amount of refraction predicted by slaRefz below 10.8 deg
**     elevation by the factor (1+0.00195*(10.8-E_t)), where E_t is the
**     unrefracted elevation in degrees.
**
**     The high-ZD model is scaled to match the normal model at the
**     transition point;  there is no glitch.
**
**  3  Beyond 93 deg zenith distance, the refraction is held at its
**     93 deg value.
**
**  4  See also the function slaRefv, which performs the adjustment in
**     Cartesian Az/El coordinates, and with the emphasis on speed
**     rather than numerical accuracy.
**
**  Defined in slamac.h:  DR2D
**
**  Reference:
**
**     Condon,J.J., 2004, Refraction Corrections for the GBT,
**     PTCS/PN/35.2, NRAO Green Bank.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaRverot ( float phi, float ra, float da, float st )
/*
**  - - - - - - - - - -
**   s l a R v e r o t
**  - - - - - - - - - -
**
**  Velocity component in a given direction due to Earth rotation.
**
**  (single precision)
**
**  Given:
**     phi     float    latitude of observing station (geodetic)
**     ra,da   float    apparent RA,Dec
**     st      float    local apparent sidereal time
**
**     phi, ra, dec and st are all in radians.
**
**  Result:
**     Component of Earth rotation in direction ra,da (km/s)
**
**  Sign convention:
**     The result is +ve when the observer is receding from the
**     given point on the sky.
**
**  Accuracy:
**     The simple algorithm used assumes a spherical Earth, of
**     a radius chosen to give results accurate to about 0.0005 km/s
**     for observing stations at typical latitudes and heights.  For
**     applications requiring greater precision, use the function
**     slaPvobs.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaRvgalc ( float r2000, float d2000 )
/*
**  - - - - - - - - - -
**   s l a R v g a l c
**  - - - - - - - - - -
**
**  Velocity component in a given direction due to the rotation
**  of the Galaxy.
**
**  (single precision)
**
**  Given:
**     r2000,d2000   float    J2000.0 mean RA,Dec (radians)
**
**  Result:
**     Component of dynamical LSR motion in direction r2000,d2000 (km/s)
**
**  Sign convention:
**     The result is +ve when the dynamical LSR is receding from the
**     given point on the sky.
**
**  Called:
**     slaCs2c, slaVdv
**
**  Note:  The Local Standard of Rest used here is a point in the
**         vicinity of the Sun which is in a circular orbit around
**         the Galactic centre.  Sometimes called the "dynamical" LSR,
**         it is not to be confused with a "kinematical" LSR, which
**         is the mean standard of rest of star catalogues or stellar
**         populations.
**
**  Reference:  The orbital speed of 220 km/s used here comes from
**              Kerr & Lynden-Bell (1986), MNRAS, 221, p1023.
**
**  Last revision:   23 March 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaRvlg ( float r2000, float d2000 )
/*
**  - - - - - - - -
**   s l a R v l g
**  - - - - - - - -
**
**  Velocity component in a given direction due to the combination
**  of the rotation of the Galaxy and the motion of the Galaxy
**  relative to the mean motion of the local group.
**
**  (single precision)
**
**  Given:
**     r2000,d2000   float    J2000.0 mean RA,Dec (radians)
**
**  Result:
**     Component of solar motion in direction r2000,d2000 (km/s)
**
**  Sign convention:
**     The result is +ve when the Sun is receding from the
**     given point on the sky.
**
**  Reference:
**     IAU trans 1976, 168, p201.
**
**  Called:
**     slaCs2c, slaVdv
**
**  Last revision:   15 July 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaRvlsrd ( float r2000, float d2000 )
/*
**  - - - - - - - - - -
**   s l a R v l s r d
**  - - - - - - - - - -
**
**  Velocity component in a given direction due to the Sun's
**  motion with respect to the dynamical Local Standard of Rest.
**
**  (single precision)
**
**  Given:
**     r2000,d2000   float    J2000.0 mean RA,Dec (radians)
**
**  Result:
**     Component of "peculiar" solar motion in direction R2000,D2000 (km/s)
**
**  Sign convention:
**     The result is +ve when the Sun is receding from the given point on
**     the sky.
**
**  Note:  The Local Standard of Rest used here is the "dynamical" LSR,
**         a point in the vicinity of the Sun which is in a circular
**         orbit around the Galactic centre.  The Sun's motion with
**         respect to the dynamical LSR is called the "peculiar" solar
**         motion.
**
**         There is another type of LSR, called a "kinematical" LSR.  A
**         kinematical LSR is the mean standard of rest of specified
**         star catalogues or stellar populations, and several slightly
**         different kinematical LSRs are in use.  The Sun's motion with
**         respect to an agreed kinematical LSR is known as the
**         "standard" solar motion.  To obtain a radial velocity
**         correction with respect to an adopted kinematical LSR use the
**         function slaRvlsrk.
**
**  Reference:  Delhaye (1965), in "Stars and Stellar Systems", vol 5, p73.
**
**  Called:  slaCs2c, slaVdv
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaRvlsrk ( float r2000, float d2000 )
/*
**  - - - - - - - - - -
**   s l a R v l s r k
**  - - - - - - - - - -
**
**  Velocity component in a given direction due to the Sun's motion
**  with respect to an adopted kinematic Local Standard of Rest.
**
**  (single precision)
**
**  Given:
**     r2000,d2000   float    J2000.0 mean RA,Dec (radians)
**
**  Result:
**     Component of "standard" solar motion in direction R2000,D2000 (km/s)
**
**  Sign convention:
**     The result is +ve when the Sun is receding from the given point
**     on the sky.
**
**  Note:  The Local Standard of Rest used here is one of several
**         "kinematical" LSRs in common use.  A kinematical LSR is the
**         mean standard of rest of specified star catalogues or stellar
**         populations.  The Sun's motion with respect to a kinematical
**         LSR is known as the "standard" solar motion.
**
**         There is another sort of LSR, the "dynamical" LSR, which is a
**         point in the vicinity of the Sun which is in a circular orbit
**         around the Galactic centre.  The Sun's motion with respect to
**         the dynamical LSR is called the "peculiar" solar motion.  To
**         obtain a radial velocity correction with respect to the
**         dynamical LSR use the function slaRvlsrd.
**
**  Reference:  Delhaye (1965), in "Stars and Stellar Systems", vol 5,
**              p73.
**
**  Called:  slaCs2c, slaVdv
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaS ( double date, double x, double y )
/*
**  - - - - -
**   s l a S
**  - - - - -
**
**  The quantity s, positioning the celestial intermediate origin on the
**  equator of the celestial intermediate pole, given the CIP's X,Y
**  coordinates.
**
**  Given:
**     date   double    TDB Modified Julian Date (Note 1)
**     x,y    double    CIP coordinates (Note 3)
**
**  Returned:
**            double    the quantity s, in radians (Note 2)
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT (or even UTC) will
**     do.
**
**  2) The CIO locator s is the difference between the right ascensions
**     of the same point in two frames:  the two systems are the ICRS
**     and the CIP,CEO, and the point is the ascending node of the
**     respective equators.  The quantity s remains below 0.1 arcsecond
**     throughout 1900-2100.
**
**  3) The series used to compute s is in fact for s+XY/2, where X and Y
**     are the x and y components of the CIP unit vector;  this series is
**     more compact than a direct series for s would be.  This function
**     requires X,Y to be supplied by the caller, who is responsible for
**     providing values that are consistent with the supplied date.
**
**  4) The model is consistent with the "P03" precession (Capitaine et
**     al. 2003).
**
**  Called:  slaDrange
**
**  Defined in slamac.h:  D2PI, DAS2R
**
**  References:
**
**     Capitaine, N., Wallace, P.T. & Chapront, J., 2003, Astronomy &
**     Astrophysics, 432, 355-357
**
**     McCarthy, D.D., Petit, G. (eds.) 2004, IERS Conventions (2003),
**     IERS Technical Note No. 32, BKG
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaS2tp ( float ra, float dec, float raz, float decz,
               float *xi, float *eta, int *j )
/*
**  - - - - - - - -
**   s l a S 2 t p
**  - - - - - - - -
**
**  Projection of spherical coordinates onto tangent plane
**  ('gnomonic' projection - 'standard coordinates').
**
**  (single precision)
**
**  Given:
**     ra,dec     float  spherical coordinates of point to be projected
**     raz,decz   float  spherical coordinates of tangent point
**
**  Returned:
**     *xi,*eta   float  rectangular coordinates on tangent plane
**     *j         int    status:   0 = OK, star on tangent plane
**                                 1 = error, star too far from axis
**                                 2 = error, antistar on tangent plane
**                                 3 = error, antistar too far from axis
**
**  Last revision:   17 August 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaSep ( float a1, float b1, float a2, float b2 )
/*
**  - - - - - - -
**   s l a S e p
**  - - - - - - -
**
**  Angle between two points on a sphere.
**
**  (single precision)
**
**  Given:
**     a1,b1     float     spherical coordinates of one point
**     a2,b2     float     spherical coordinates of the other point
**
**  (The spherical coordinates are [RA,Dec], [Long,Lat] etc, in radians.)
**
**  The result is the angle, in radians, between the two points.  It is
**  always positive.
**
**  Called:  slaDsep
**
**  Last revision:   7 May 2000
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaSepv ( float v1[3], float v2[3] )
/*
**  - - - - - - - -
**   s l a S e p v
**  - - - - - - - -
**
**  Angle between two vectors.
**
**  (single precision)
**
**  Given:
**     v1     float[3]     first vector
**     v2     float[3]     second vector
**
**  The result is the angle, in radians, between the two vectors.  It
**  is always positive.
**
**  Notes:
**
**  1  There is no requirement for the vectors to be unit length.
**
**  2  If either vector is null, zero is returned.
**
**  3  The simplest formulation would use dot product alone.  However,
**     this would reduce the accuracy for angles near zero and pi.  The
**     algorithm uses both cross product and dot product, which maintains
**     accuracy for all sizes of angle.
**
**  Called:  slaDsepv
**
**  Last revision:   7 May 2000
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaSmat ( int n, float *a, float *y, float *d, int *jf, int *iw )
/*
**  - - - - - - - -
**   s l a S m a t
**  - - - - - - - -
**
**  Matrix inversion & solution of simultaneous equations.
**
**  (single precision)
**
**  For the set of n simultaneous equations in n unknowns:
**     a.y = x
**
**  where:
**     a is a non-singular n x n matrix
**     y is the vector of n unknowns
**     x is the known vector
**
**  slaSmat computes:
**     the inverse of matrix a
**     the determinant of matrix a
**     the vector of n unknowns
**
**  Arguments:
**
**     symbol  type dimension           before              after
**
**       n      int                  no. of unknowns       unchanged
**       *a     float  [n][n]            matrix             inverse
**       *y     float   [n]              vector            solution
**       *d     float                      -              determinant
**    >  *jf    int                        -            singularity flag
**       *iw    int     [n]                -               workspace
**
**
**    > jf is the singularity flag.  If the matrix is non-singular,
**      jf=0 is returned.  If the matrix is singular, jf=-1 & d=0.0 are
**      returned.  In the latter case, the contents of array a on return
**      are undefined.
**
**  Algorithm:
**     Gaussian elimination with partial pivoting.
**
**  Speed:
**     Very fast.
**
**  Accuracy:
**     Fairly accurate - errors 1 to 4 times those of functions
**     optimized for accuracy.
**
**  Example call (note handling of "adjustable dimension" 2D array):
**
**     float a[MP][MP], v[MP], d;
**     int j, iw[MP];
**      :
**     slaSmat ( n, (float *) a, v, &d, &j, iw );
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaSp ( double date )
/*
**  - - - - - -
**   s l a S p
**  - - - - - -
**
**  The quantity s', positioning the terrestrial intermediate origin on
**  the equator of the intermediate pole.
**
**  Given:
**     date      double   date, TDB Modified Julian Date (Note 1)
**
**  Returned:
**     slaSp00   double   the quantity s' in radians (Note 2)
**
**  Notes:
**
**  1) The date is TDB as an MJD (=JD-2400000.5).  TT (or even UTC) will
**     do.
**
**  2) The quantity s' is obtained from polar motion observations by
**     numerical integration, and so is in essence unpredictable.
**     However, it is dominated by a secular drift of about
**     47 microarcseconds per century, which is the approximation
**     evaluated by the present function.
**
**  Defined in slamac.h:  DAS2R
**
**  Reference:
**
**     McCarthy, D.D., Petit, G. (eds.) 2004, IERS Conventions (2003),
**     IERS Technical Note No. 32, BKG
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaSubet ( double rc, double dc, double eq, double *rm, double *dm )
/*
**  - - - - - - - - -
**   s l a S u b e t
**  - - - - - - - - -
**
**  Remove the e-terms (elliptic component of annual aberration)
**  from a pre IAU 1976 catalogue RA,Dec to give a mean place.
**
**  (double precision)
**
**  Given:
**     rc,dc     double     RA,Dec (radians) with e-terms included
**     eq        double     Besselian epoch of mean equator and equinox
**
**  Returned:
**     *rm,*dm   double     RA,Dec (radians) without e-terms
**
**  Called:
**     slaEtrms, slaDcs2c, sla,dvdv, slaDcc2s, slaDranrm
**
**  Explanation:
**     Most star positions from pre-1984 optical catalogues (or
**     derived from astrometry using such stars) embody the
**     e-terms.  This function converts such a position to a
**     formal mean place (allowing, for example, comparison with a
**     pulsar timing position).
**
**  Reference:
**     Explanatory Supplement to the Astronomical Ephemeris,
**     section 2D, page 48.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaSupgal ( double dsl, double dsb, double *dl, double *db )
/*
**  - - - - - - - - - -
**   s l a S u p g a l
**  - - - - - - - - - -
**
**  Transformation from De Vaucouleurs supergalactic coordinates
**  to IAU 1958 Galactic coordinates.
**
**  (double precision)
**
**  Given:
**     dsl,dsb     double      supergalactic longitude and latitude
**
**  Returned:
**     *dl,*db     double      Galactic longitude and latitude l2,b2
**
**  (all arguments are radians)
**
**  Called:
**     slaDcs2c, slaDimxv, slaDcc2s, slaDranrm, slaDrange
**
**  References:
**
**     De Vaucouleurs, De Vaucouleurs, & Corwin, Second Reference
**     Catalogue of Bright Galaxies, U. Texas, page 8.
**
**     Systems & Applied Sciences Corp., Documentation for the
**     machine-readable version of the above catalogue,
**     contract NAS 5-26490.
**
**    (These two references give different values for the Galactic
**     longitude of the supergalactic origin.  Both are wrong;  the
**     correct value is l2=137.37.)
**
**  Last revision:   8 December 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double rms ( double a, double b );
void slaSvd ( int m, int n, int mp, int np, double *a, double *w,
              double *v, double *work, int *jstat )
/*
**  - - - - - - -
**   s l a S v d
**  - - - - - - -
**
**  Singular value decomposition.
**
**  (double precision)
**
**  This function expresses a given matrix a as the product of
**  three matrices u, w, v:
**
**     a = u x w x vt
**
**  where:
**
**     a   is any m (rows) x n (columns) matrix, where m >= n
**     u   is an m x n column-orthogonal matrix
**     w   is an n x n diagonal matrix with w(i,i) >= 0
**     vt  is the transpose of an n x n orthogonal matrix
**
**     Note that m and n, above, are the logical dimensions of the
**     matrices and vectors concerned, which can be located in
**     arrays of larger physical dimensions, given by mp and np.
**
**  Given:
**     m,n    int            numbers of rows and columns in matrix a
**     mp,np  int            physical dimensions of the array containing a
**     a      double[mp,np]  array containing m x n matrix a
**
**  Returned:
**     *a     double[mp,np]  array containing m x n column-orthogonal matrix u
**     *w     double[n]      n x n diagonal matrix w (diagonal elements only)
**     *v     double[np,np]  array containing n x n orthogonal matrix v
**     *work  double[n]      workspace
**     *jstat int            0 = OK
**                          -1 = the a array is the wrong shape
**                          >0 = 1 + index of w for which convergence failed.
**
**     (n.b. v contains matrix v, not the transpose of matrix v)
**
**  References:
**     The algorithm is an adaptation of the SVD subroutine in the
**     EISPACK library (Garbow et al 1977, Eispack guide extension,
**     Springer Verlag), which is a Fortran 66 implementation of the
**     Algol procedure SVD of Wilkinson & Reinsch 1971 (Handbook for
**     Automatic Computation, vol 2, Ed Bauer et al, Springer Verlag).
**     For the non-specialist, probably the clearest general account of
**     the use of SVD in least squares problems is given in Numerical
**     Recipes (Press et al 1986, Cambridge University Press).
**
**  From slamac.h:  TRUE, FALSE
**
**  Example call (note handling of "adjustable dimension" 2D arrays):
**
**    double a[mp][np], w[np], v[np][np], work[np];
**    int m, n, j;
**     :
**    slaSvd ( m, n, mp, np, (double*) a, w, (double*) v, work, &j );
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaSvdcov ( int n, int np, int nc, double *w, double *v,
                 double *work, double *cvm )
/*
**  - - - - - - - - - -
**   s l a S v d c o v
**  - - - - - - - - - -
**
**  From the w and v matrices from the SVD factorization of a matrix
**  (as obtained from the slaSvd function), obtain the covariance matrix.
**
**  (double precision)
**
**  Given:
**     n      int            number of rows and columns in matrices w and v
**     np     int            first dimension of array containing matrix v
**     nc     int            first dimension of array to receive cvm
**     *w     double[n]      nxn diagonal matrix w (diagonal elements only)
**     *v     double[np][np] array containing nxn orthogonal matrix v
**
**  Returned:
**     *work  double[n]      workspace
**     *cvm   double[nc][nc] array to receive covariance matrix
**
**  Reference:
**     Numerical Recipes, Section 14.3.
**
**  Example call (note handling of "adjustable dimension" 2D arrays):
**
**    double w[np], v[np][np], work[np], c[np][np];
**    int n;
**     :
**    slaSvdcov ( n, np, nc, w, (double*) v, work, (double*) c );
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaSvdsol ( int m, int n, int mp, int np, double *b, double *u,
                 double *w, double *v, double *work, double *x )
/*
**  - - - - - - - - - -
**   s l a S v d s o l
**  - - - - - - - - - -
**
**  From a given vector and the SVD of a matrix (as obtained from
**  the slaSvd function), obtain the solution vector.
**
**  (double precision)
**
**  This function solves the equation:
**
**     a . x = b
**
**  where:
**
**     a   is a given m (rows) x n (columns) matrix, where m.ge.n
**     x   is the n-vector we wish to find
**     b   is a given m-vector
**
**  By means of the singular value decomposition method (SVD).  In
**  this method, the matrix a is first factorized (for example by
**  the function slaSvd) into the following components:
**
**     a = u x w x vt
**
**  where:
**
**     a   is the m (rows) x n (columns) matrix
**     u   is an m x n column-orthogonal matrix
**     w   is an n x n diagonal matrix with w(i,i).ge.0
**     vt  is the transpose of an nxn orthogonal matrix
**
**     Note that m and n, above, are the logical dimensions of the
**     matrices and vectors concerned, which can be located in
**     arrays of larger physical dimensions mp and np.
**
**  The solution is found from the expression:
**
**     x = v . [diag(1/wj)] . ( transpose(u) . b )
**
**  Notes:
**
**  1)  If matrix a is square, and if the diagonal matrix w is not
**      adjusted, the method is equivalent to conventional solution
**      of simultaneous equations.
**
**  2)  If m>n, the result is a least-squares fit.
**
**  3)  If the solution is poorly determined, this shows up in the
**      SVD factorization as very small or zero wj values.  Where
**      a wj value is small but non-zero it can be set to zero to
**      avoid ill effects.  The present function detects such zero
**      wj values and produces a sensible solution, with highly
**      correlated terms kept under control rather than being allowed
**      to elope to infinity, and with meaningful values for the
**      other terms.
**
**  Given:
**     m,n    int            numbers of rows and columns in matrix a
**     mp,np  int            physical dimensions of array containing matrix a
**     *b     double[m]      known vector b
**     *u     double[mp][np] array containing mxn matrix u
**     *w     double[n]      nxn diagonal matrix w (diagonal elements only)
**     *v     double[np][np] array containing nxn orthogonal matrix v
**
**  Returned:
**     *work  double[n]      workspace
**     *x     double[n]      unknown vector x
**
**  Note:  If the relative sizes of m, n, mp and np are inconsistent,
**         the vector x is returned unaltered.  This condition should
**         have been detected when the SVD was performed using slaSvd.
**
**  Reference:
**     Numerical Recipes, Section 2.9.
**
**  Example call (note handling of "adjustable dimension" 2D arrays):
**
**    double a[mp][np], w[np], v[np][np], work[np], b[mp], x[np];
**    int m, n;
**     :
**    slaSvdsol ( m, n, mp, np, b, (double*) a, w, (double*) v, work, x );
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaTp2s ( float xi, float eta, float raz, float decz,
               float *ra, float *dec )
/*
**  - - - - - - - -
**   s l a T p 2 s
**  - - - - - - - -
**
**  Transform tangent plane coordinates into spherical.
**
**  (single precision)
**
**  Given:
**     xi,eta      float  tangent plane rectangular coordinates
**     raz,decz    float  spherical coordinates of tangent point
**
**  Returned:
**     *ra,*dec    float  spherical coordinates (0-2pi,+/-pi/2)
**
**  Called:        slaRanorm
**
**  Last revision:   10 July 1994
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaTp2v ( float xi, float eta, float v0[3], float v[3] )
/*
**  - - - - - - - -
**   s l a T p 2 v
**  - - - - - - - -
**
**  Given the tangent-plane coordinates of a star and the direction
**  cosines of the tangent point, determine the direction cosines
**  of the star.
**
**  (single precision)
**
**  Given:
**     xi,eta    float      tangent plane coordinates of star
**     v0        float[3]   direction cosines of tangent point
**
**  Returned:
**     v         float[3]   direction cosines of star
**
**  Notes:
**
**  1  If vector v0 is not of unit length, the returned vector v will
**     be wrong.
**
**  2  If vector v0 points at a pole, the returned vector v will be
**     based on the arbitrary assumption that the RA of the tangent
**     point is zero.
**
**  3  This function is the Cartesian equivalent of the function
**     slaTp2s.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaTps2c ( float xi, float eta, float ra, float dec,
                float *raz1, float *decz1,
                float *raz2, float *decz2, int *n )
/*
**  - - - - - - - - -
**   s l a T p s 2 c
**  - - - - - - - - -
**
**  From the tangent plane coordinates of a star of known RA,Dec,
**  determine the RA,Dec of the tangent point.
**
**  (single precision)
**
**  Given:
**     xi,eta       float tangent plane rectangular coordinates
**     ra,dec       float spherical coordinates
**
**  Returned:
**     *raz1,*decz1 float spherical coordinates of TP, solution 1
**     *raz2,*decz2 float spherical coordinates of TP, solution 2
**     *n           int   number of solutions:
**                         0 = no solutions returned (note 2)
**                         1 = only the first solution is useful (note 3)
**                         2 = both solutions are useful (note 3)
**
**  Notes:
**
**  1  The raz1 and raz2 values are returned in the range 0-2pi.
**
**  2  Cases where there is no solution can only arise near the poles.
**     For example, it is clearly impossible for a star at the pole
**     itself to have a non-zero xi value, and hence it is
**     meaningless to ask where the tangent point would have to be
**     to bring about this combination of xi and dec.
**
**  3  Also near the poles, cases can arise where there are two useful
**     solutions.  The argument n indicates whether the second of the
**     two solutions returned is useful;  n=1 indicates only one useful
**     solution, the usual case;  under these circumstances, the second
**     solution corresponds to the "beyond the pole" case, and this is
**     reflected in the values of raz2 and decz2 which are returned.
**
**  4  The decz1 and decz2 values are returned in the range +/-pi, but
**     in the usual, non-pole-crossing, case, the range is +/-pi/2.
**
**  5  This function is the spherical equivalent of the function
**     slaTpv2c.
**
**  Called:  slaRanorm
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaTpv2c ( float xi, float eta, float v[3], float v01[3],
                                                 float v02[3], int *n )
/*
**  - - - - - - - - -
**   s l a T p v 2 c
**  - - - - - - - - -
**
**  Given the tangent-plane coordinates of a star and its direction
**  cosines, determine the direction cosines of the tangent-point.
**
**  (single precision)
**
**  Given:
**     xi,eta  float     tangent plane coordinates of star
**     v       float[3]  direction cosines of star
**
**  Returned:
**     v01     float[3]  direction cosines of TP, solution 1
**     v02     float[3]  direction cosines of TP, solution 2
**     *n      int       number of solutions:
**                        0 = no solutions returned (note 2)
**                        1 = only the first solution is useful (note 3)
**                        2 = both solutions are useful (note 3)
**
**  Notes:
**
**  1  The vector v must be of unit length or the result will be wrong.
**
**  2  Cases where there is no solution can only arise near the poles.
**     For example, it is clearly impossible for a star at the pole
**     itself to have a non-zero xi value, and hence it is meaningless
**     to ask where the tangent point would have to be.
**
**  3  Also near the poles, cases can arise where there are two useful
**     solutions.  The argument n indicates whether the second of the
**     two solutions returned is useful;  n=1 indicates only one useful
**     solution, the usual case.  Under these circumstances, the second
**     solution can be regarded as valid if the vector v02 is
**     interpreted as the "beyond the pole" case.
**
**  4  This function is the Cartesian equivalent of the function
**     slaTps2c.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaUe2el ( double u[], int jformr,
                int *jform, double *epoch, double *orbinc,
                double *anode, double *perih, double *aorq, double *e,
                double *aorl, double *dm, int *jstat )
/*
**  - - - - - - - - -
**   s l a U e 2 e l
**  - - - - - - - - -
**
**  Transform universal elements into conventional heliocentric
**  osculating elements.
**
**  Given:
**
**     u       double[13] universal orbital elements (Note 1)
**
**                    [0] combined mass (M+m)
**                    [1] total energy of the orbit (alpha)
**                    [2] reference (osculating) epoch (t0)
**                  [3-5] position at reference epoch (r0)
**                  [6-8] velocity at reference epoch (v0)
**                    [9] heliocentric distance at reference epoch
**                   [10] r0.v0
**                   [11] date (t)
**                   [12] universal eccentric anomaly (psi) of date, approx
**
**     jformr  int        requested element set (1-3; Note 3)
**
**  Returned:
**     jform   double*    element set actually returned (1-3; Note 4)
**     epoch   double*    epoch of elements (TT MJD)
**     orbinc  double*    inclination (radians)
**     anode   double*    longitude of the ascending node (radians)
**     perih   double*    longitude or argument of perihelion (radians)
**     aorq    double*    mean distance or perihelion distance (AU)
**     e       double*    eccentricity
**     aorl    double*    mean anomaly or longitude (radians, jform=1,2 only)
**     dm      double*    daily motion (radians, jform=1 only)
**     jstat   int*       status:  0 = OK
**                                -1 = illegal combined mass
**                                -2 = illegal jformr
**                                -3 = position/velocity out of range
**
**  Notes
**
**  1  The "universal" elements are those which define the orbit for the
**     purposes of the method of universal variables (see reference 2).
**     They consist of the combined mass of the two bodies, an epoch,
**     and the position and velocity vectors (arbitrary reference frame)
**     at that epoch.  The parameter set used here includes also various
**     quantities that can, in fact, be derived from the other
**     information.  This approach is taken to avoiding unnecessary
**     computation and loss of accuracy.  The supplementary quantities
**     are (i) alpha, which is proportional to the total energy of the
**     orbit, (ii) the heliocentric distance at epoch, (iii) the
**     outwards component of the velocity at the given epoch, (iv) an
**     estimate of psi, the "universal eccentric anomaly" at a given
**     date and (v) that date.
**
**  2  The universal elements are with respect to the mean equator and
**     equinox of epoch J2000.  The orbital elements produced are with
**     respect to the J2000 ecliptic and mean equinox.
**
**  3  Three different element-format options are supported:
**
**     Option jform=1, suitable for the major planets:
**
**     epoch  = epoch of elements (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = longitude of perihelion, curly pi (radians)
**     aorq   = mean distance, a (AU)
**     e      = eccentricity, e
**     aorl   = mean longitude L (radians)
**     dm     = daily motion (radians)
**
**     Option jform=2, suitable for minor planets:
**
**     epoch  = epoch of elements (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = argument of perihelion, little omega (radians)
**     aorq   = mean distance, a (AU)
**     e      = eccentricity, e
**     aorl   = mean anomaly M (radians)
**
**     Option jform=3, suitable for comets:
**
**     epoch  = epoch of perihelion (TT MJD)
**     orbinc = inclination i (radians)
**     anode  = longitude of the ascending node, big omega (radians)
**     perih  = argument of perihelion, little omega (radians)
**     aorq   = perihelion distance, q (AU)
**     e      = eccentricity, e
**
**  4  It may not be possible to generate elements in the form
**     requested through jformr.  The caller is notified of the form
**     of elements actually returned by means of the jform argument:
**
**      jformr   jform     meaning
**
**        1        1       OK - elements are in the requested format
**        1        2       never happens
**        1        3       orbit not elliptical
**
**        2        1       never happens
**        2        2       OK - elements are in the requested format
**        2        3       orbit not elliptical
**
**        3        1       never happens
**        3        2       never happens
**        3        3       OK - elements are in the requested format
**
**  5  The arguments returned for each value of jform (cf Note 6: jform
**     may not be the same as jformr) are as follows:
**
**         jform         1              2              3
**         epoch         t0             t0             T
**         orbinc        i              i              i
**         anode         Omega          Omega          Omega
**         perih         curly pi       omega          omega
**         aorq          a              a              q
**         e             e              e              e
**         aorl          L              M              -
**         dm            n              -              -
**
**     where:
**
**         t0           is the epoch of the elements (MJD, TT)
**         T              "    epoch of perihelion (MJD, TT)
**         i              "    inclination (radians)
**         Omega          "    longitude of the ascending node (radians)
**         curly pi       "    longitude of perihelion (radians)
**         omega          "    argument of perihelion (radians)
**         a              "    mean distance (AU)
**         q              "    perihelion distance (AU)
**         e              "    eccentricity
**         L              "    longitude (radians, 0-2pi)
**         M              "    mean anomaly (radians, 0-2pi)
**         n              "    daily motion (radians)
**         -             means no value is set
**
**  6  At very small inclinations, the longitude of the ascending node
**     anode becomes indeterminate and under some circumstances may be
**     set arbitrarily to zero.  Similarly, if the orbit is close to
**     circular, the true anomaly becomes indeterminate and under some
**     circumstances may be set arbitrarily to zero.  In such cases,
**     the other elements are automatically adjusted to compensate,
**     and so the elements remain a valid description of the orbit.
**
**  References:
**
**     1  Sterne, Theodore E., "An Introduction to Celestial Mechanics",
**        Interscience Publishers Inc., 1960.  Section 6.7, p199.
**
**     2  Everhart, E. & Pitkin, E.T., Am.J.Phys. 51, 712, 1983.
**
**  Called:  slaPv2el
**
**  Last revision:   18 March 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaUe2pv ( double date, double u[], double pv[], int *jstat )
/*
**  - - - - - - - - -
**   s l a U e 2 p v
**  - - - - - - - - -
**
**  Heliocentric position and velocity of a planet, asteroid or comet,
**  starting from orbital elements in the "universal variables" form.
**
**  Given:
**     date    double     date, Modified Julian Date (JD-2400000.5)
**
**  Given and returned:
**     u       double[13] universal orbital elements (updated; Note 1)
**
**         given      [0] combined mass (M+m)
**           "        [1] total energy of the orbit (alpha)
**           "        [2] reference (osculating) epoch (t0)
**           "      [3-5] position at reference epoch (r0)
**           "      [6-8] velocity at reference epoch (v0)
**           "        [9] heliocentric distance at reference epoch
**           "       [10] r0.v0
**       returned    [11] date (t)
**           "       [12] universal eccentric anomaly (psi) of date, approx
**
**  Returned:
**     pv      double[6]  position (AU) and velocity (AU/s)
**     jstat   int*       status:  0 = OK
**                                -1 = radius vector zero
**                                -2 = failed to converge
**
**  Notes
**
**  1  The "universal" elements are those which define the orbit for the
**     purposes of the method of universal variables (see reference).
**     They consist of the combined mass of the two bodies, an epoch,
**     and the position and velocity vectors (arbitrary reference frame)
**     at that epoch.  The parameter set used here includes also various
**     quantities that can, in fact, be derived from the other
**     information.  This approach is taken to avoiding unnecessary
**     computation and loss of accuracy.  The supplementary quantities
**     are (i) alpha, which is proportional to the total energy of the
**     orbit, (ii) the heliocentric distance at epoch, (iii) the
**     outwards component of the velocity at the given epoch, (iv) an
**     estimate of psi, the "universal eccentric anomaly" at a given
**     date and (v) that date.
**
**  2  The companion function is slaEl2ue.  This takes the conventional
**     orbital elements and transforms them into the set of numbers
**     needed by the present function.  A single prediction requires one
**     one call to slaEl2ue followed by one call to the present
**     function; for convenience, the two calls are packaged as the
**     function slaPlanel.   Multiple predictions may be made by again
**     calling slaEl2ue once, but then calling the present function
**     multiple times, which is faster than multiple calls to slaPlanel.
**
**     It is not obligatory to use slaEl2ue to obtain the parameters.
**     However, it should be noted that because slaEl2ue performs its
**     own validation, no checks on the contents of the array U are made
**     by the present function.
**
**  3  date is the instant for which the prediction is required.  It is
**     in the TT timescale (formerly Ephemeris Time, ET) and is a
**     Modified Julian Date (JD-2400000.5).
**
**  4  The universal elements supplied in the array u are in canonical
**     units (solar masses, AU and canonical days).  The position and
**     velocity are not sensitive to the choice of reference frame.  The
**     slaEl2ue function in fact produces coordinates with respect to
**     the J2000 equator and equinox.
**
**  5  The algorithm was originally adapted from the EPHSLA program of
**     D.H.P.Jones (private communication, 1996).  The method is based
**     on Stumpff's Universal Variables.
**
**  Reference:  Everhart, E. & Pitkin, E.T., Am.J.Phys. 51, 712, 1983.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaUnpcd ( double disco, double *x, double *y )
/*
**  - - - - - - - - -
**   s l a U n p c d
**  - - - - - - - - -
**
**  Remove pincushion/barrel distortion from a distorted [x,y] to give
**  tangent-plane [x,y].
**
**  Given:
**     disco    double      pincushion/barrel distortion coefficient
**     x,y      double*     distorted coordinates
**
**  Returned:
**     x,y      double*     tangent-plane coordinates
**
**  Defined in slamac.h:
**     D2PI     double      2*pi
**
**  Notes:
**
**   1)  The distortion is of the form RP = R*(1 + C*R^2), where R is
**       the radial distance from the tangent point, C is the disco
**       argument, and RP is the radial distance in the presence of
**       the distortion.
**
**   2)  For pincushion distortion, C is +ve;  for barrel distortion,
**       C is -ve.
**
**   3)  For x,y in "radians" - units of one projection radius,
**       which in the case of a photograph is the focal length of
**       the camera - the following disco values apply:
**
**           geometry          disco
**
**           astrograph         0.0
**           schmidt           -0.3333
**           AAT PF doublet  +147.069
**           AAT PF triplet  +178.585
**           AAT f/8          +21.20
**           JKT f/8          +13.32
**
**   4)  The present function is a rigorous inverse of the companion
**       function slaPcd.  The expression for RP in Note 1 is rewritten
**       in the form x^3+a*x+b=0 and solved by standard techniques.
**
**   5)  Cases where the cubic has multiple real roots can sometimes
**       occur, corresponding to extreme instances of barrel distortion
**       where up to three different undistorted [X,Y]s all produce the
**       same distorted [X,Y].  However, only one solution is returned,
**       the one that produces the smallest change in [X,Y].
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaV2tp ( float v[3], float v0[3], float *xi, float *eta, int *j )
/*
**  - - - - - - - -
**   s l a V 2 t p
**  - - - - - - - -
**
**  Given the direction cosines of a star and of the tangent point,
**  determine the star's tangent-plane coordinates.
**
**  (single precision)
**
**  Given:
**     v        float[3] direction cosines of star
**     v0       float[3] direction cosines of tangent point
**
**  Returned:
**     *xi,*eta float    tangent plane coordinates of star
**     j        int      status: 0  =  OK
**                               1  =  error, star too far from axis
**                               2  =  error, antistar on tangent plane
**                               3  =  error, antistar too far from axis
**
**  Notes:
**
**  1  If vector v0 is not of unit length, or if vector v is of zero
**     length, the results will be wrong.
**
**  2  If v0 points at a pole, the returned xi,eta will be based on the
**     arbitrary assumption that the RA of the tangent point is zero.
**
**  3  This function is the Cartesian equivalent of the function
**     slaS2tp.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


float slaVdv ( float va[3], float vb[3] )
/*
**  - - - - - - -
**   s l a V d v
**  - - - - - - -
**
**  Scalar product of two 3-vectors.
**
**  (single precision)
**
**  Given:
**      va      float[3]     first vector
**      vb      float[3]     second vector
**
**  The result is the scalar product va.vb  (single precision).
**
**  Last revision:   15 July 1993
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaVn ( float v[3], float uv[3], float *vm )
/*
**  - - - - - -
**   s l a V n
**  - - - - - -
**
**  Normalizes a 3-vector also giving the modulus.
**
**  (single precision)
**
**  Given:
**     v       float[3]      vector
**
**  Returned:
**     uv      float[3]      unit vector in direction of v
**     *vm     float         modulus of v
**
**  Note:  v and uv may be the same array.
**
**  If the modulus of v is zero, uv is set to zero as well.
**
**  Last revision:   6 November 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaVxv ( float va[3], float vb[3], float vc[3] )
/*
**  - - - - - - -
**   s l a V x v
**  - - - - - - -
**
**  Vector product of two 3-vectors.
**
**  (single precision)
**
**  Given:
**     va      float[3]     first vector
**     vb      float[3]     second vector
**
**  Returned:
**     vc      float[3]     vector result
**
**  Note:  the same vector may be specified more than once.
**
**  Last revision:   6 November 1999
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


void slaXy2xy ( double xc1, double yc1, double coeffs[6],
                double *xc2, double *yc2 )
/*
**  - - - - - - - - -
**   s l a X y 2 x y
**  - - - - - - - - -
**
**  Transform one [x,y] into another using a linear model of the type
**  produced by the slaFitxy function.
**
**  Given:
**     xc1      double        x-coordinate
**     yc1      double        y-coordinate
**     coeffs   double[6]     transformation coefficients (see note)
**
**  Returned:
**     *xc2     double        x-coordinate
**     *yc2     double        y-coordinate
**
**  The model relates two sets of [x,y] coordinates as follows.
**  Naming the elements of coeffs:
**
**     coeffs[0] = a
**     coeffs[1] = b
**     coeffs[2] = c
**     coeffs[3] = d
**     coeffs[4] = e
**     coeffs[5] = f
**
**  the present function performs the transformation:
**
**     xc2 = a + b*xc1 + c*yc1
**     yc2 = d + e*xc1 + f*yc1
**
**  See also slaFitxy, slaPxy, slaInvf, slaDcmpf.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/


double slaZd ( double ha, double dec, double phi )
/*
**  - - - - - -
**   s l a Z d
**  - - - - - -
**
**  HA, Dec to Zenith Distance.
**
**  (double precision)
**
**  Given:
**     ha     double     Hour Angle in radians
**     dec    double     declination in radians
**     phi    double     observatory latitude in radians
**
**  The result is in the range 0 to pi.
**
**  Notes:
**
**  1)  The latitude must be geodetic.  In critical applications,
**      corrections for polar motion should be applied.
**
**  2)  In some applications it will be important to specify the
**      correct type of hour angle and declination in order to
**      produce the required type of zenith distance.  In particular,
**      it may be important to distinguish between the zenith distance
**      as affected by refraction, which would require the "observed"
**      HA,Dec, and the zenith distance in vacuo, which would require
**      the "topocentric" HA,Dec.  If the effects of diurnal aberration
**      can be neglected, the "apparent" HA,Dec may be used instead of
**      the topocentric HA,Dec.
**
**  3)  No range checking of arguments is done.
**
**  4)  In applications which involve many zenith distance calculations,
**      rather than calling the present function it will be more
**      efficient to use inline code, having previously computed fixed
**      terms such as sine and cosine of latitude, and perhaps sine and
**      cosine of declination.
**
**  Last revision:   22 October 2006
**
**  Copyright P.T.Wallace.  All rights reserved.
*/
