| 1 | #include "erfa.h" | 
|---|
| 2 |  | 
|---|
| 3 | void eraC2s(double p[3], double *theta, double *phi) | 
|---|
| 4 | /* | 
|---|
| 5 | **  - - - - - - - | 
|---|
| 6 | **   e r a C 2 s | 
|---|
| 7 | **  - - - - - - - | 
|---|
| 8 | ** | 
|---|
| 9 | **  P-vector to spherical coordinates. | 
|---|
| 10 | ** | 
|---|
| 11 | **  Given: | 
|---|
| 12 | **     p      double[3]    p-vector | 
|---|
| 13 | ** | 
|---|
| 14 | **  Returned: | 
|---|
| 15 | **     theta  double       longitude angle (radians) | 
|---|
| 16 | **     phi    double       latitude angle (radians) | 
|---|
| 17 | ** | 
|---|
| 18 | **  Notes: | 
|---|
| 19 | ** | 
|---|
| 20 | **  1) The vector p can have any magnitude; only its direction is used. | 
|---|
| 21 | ** | 
|---|
| 22 | **  2) If p is null, zero theta and phi are returned. | 
|---|
| 23 | ** | 
|---|
| 24 | **  3) At either pole, zero theta is returned. | 
|---|
| 25 | ** | 
|---|
| 26 | **  Copyright (C) 2013-2017, NumFOCUS Foundation. | 
|---|
| 27 | **  Derived, with permission, from the SOFA library.  See notes at end of file. | 
|---|
| 28 | */ | 
|---|
| 29 | { | 
|---|
| 30 | double x, y, z, d2; | 
|---|
| 31 |  | 
|---|
| 32 |  | 
|---|
| 33 | x  = p[0]; | 
|---|
| 34 | y  = p[1]; | 
|---|
| 35 | z  = p[2]; | 
|---|
| 36 | d2 = x*x + y*y; | 
|---|
| 37 |  | 
|---|
| 38 | *theta = (d2 == 0.0) ? 0.0 : atan2(y, x); | 
|---|
| 39 | *phi = (z == 0.0) ? 0.0 : atan2(z, sqrt(d2)); | 
|---|
| 40 |  | 
|---|
| 41 | return; | 
|---|
| 42 |  | 
|---|
| 43 | } | 
|---|
| 44 | /*---------------------------------------------------------------------- | 
|---|
| 45 | ** | 
|---|
| 46 | ** | 
|---|
| 47 | **  Copyright (C) 2013-2017, NumFOCUS Foundation. | 
|---|
| 48 | **  All rights reserved. | 
|---|
| 49 | ** | 
|---|
| 50 | **  This library is derived, with permission, from the International | 
|---|
| 51 | **  Astronomical Union's "Standards of Fundamental Astronomy" library, | 
|---|
| 52 | **  available from http://www.iausofa.org. | 
|---|
| 53 | ** | 
|---|
| 54 | **  The ERFA version is intended to retain identical functionality to | 
|---|
| 55 | **  the SOFA library, but made distinct through different function and | 
|---|
| 56 | **  file names, as set out in the SOFA license conditions.  The SOFA | 
|---|
| 57 | **  original has a role as a reference standard for the IAU and IERS, | 
|---|
| 58 | **  and consequently redistribution is permitted only in its unaltered | 
|---|
| 59 | **  state.  The ERFA version is not subject to this restriction and | 
|---|
| 60 | **  therefore can be included in distributions which do not support the | 
|---|
| 61 | **  concept of "read only" software. | 
|---|
| 62 | ** | 
|---|
| 63 | **  Although the intent is to replicate the SOFA API (other than | 
|---|
| 64 | **  replacement of prefix names) and results (with the exception of | 
|---|
| 65 | **  bugs;  any that are discovered will be fixed), SOFA is not | 
|---|
| 66 | **  responsible for any errors found in this version of the library. | 
|---|
| 67 | ** | 
|---|
| 68 | **  If you wish to acknowledge the SOFA heritage, please acknowledge | 
|---|
| 69 | **  that you are using a library derived from SOFA, rather than SOFA | 
|---|
| 70 | **  itself. | 
|---|
| 71 | ** | 
|---|
| 72 | ** | 
|---|
| 73 | **  TERMS AND CONDITIONS | 
|---|
| 74 | ** | 
|---|
| 75 | **  Redistribution and use in source and binary forms, with or without | 
|---|
| 76 | **  modification, are permitted provided that the following conditions | 
|---|
| 77 | **  are met: | 
|---|
| 78 | ** | 
|---|
| 79 | **  1 Redistributions of source code must retain the above copyright | 
|---|
| 80 | **    notice, this list of conditions and the following disclaimer. | 
|---|
| 81 | ** | 
|---|
| 82 | **  2 Redistributions in binary form must reproduce the above copyright | 
|---|
| 83 | **    notice, this list of conditions and the following disclaimer in | 
|---|
| 84 | **    the documentation and/or other materials provided with the | 
|---|
| 85 | **    distribution. | 
|---|
| 86 | ** | 
|---|
| 87 | **  3 Neither the name of the Standards Of Fundamental Astronomy Board, | 
|---|
| 88 | **    the International Astronomical Union nor the names of its | 
|---|
| 89 | **    contributors may be used to endorse or promote products derived | 
|---|
| 90 | **    from this software without specific prior written permission. | 
|---|
| 91 | ** | 
|---|
| 92 | **  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
|---|
| 93 | **  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
|---|
| 94 | **  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 
|---|
| 95 | **  FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE | 
|---|
| 96 | **  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|---|
| 97 | **  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 
|---|
| 98 | **  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 
|---|
| 99 | **  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
|---|
| 100 | **  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 
|---|
| 101 | **  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 
|---|
| 102 | **  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
|---|
| 103 | **  POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 104 | ** | 
|---|
| 105 | */ | 
|---|