| 1 | #include "sofa.h"
|
|---|
| 2 |
|
|---|
| 3 | int iauGc2gde ( double a, double f, double xyz[3],
|
|---|
| 4 | double *elong, double *phi, double *height )
|
|---|
| 5 | /*
|
|---|
| 6 | ** - - - - - - - - - -
|
|---|
| 7 | ** i a u G c 2 g d e
|
|---|
| 8 | ** - - - - - - - - - -
|
|---|
| 9 | **
|
|---|
| 10 | ** Transform geocentric coordinates to geodetic for a reference
|
|---|
| 11 | ** ellipsoid of specified form.
|
|---|
| 12 | **
|
|---|
| 13 | ** This function is part of the International Astronomical Union's
|
|---|
| 14 | ** SOFA (Standards of Fundamental Astronomy) software collection.
|
|---|
| 15 | **
|
|---|
| 16 | ** Status: support function.
|
|---|
| 17 | **
|
|---|
| 18 | ** Given:
|
|---|
| 19 | ** a double equatorial radius (Notes 2,4)
|
|---|
| 20 | ** f double flattening (Note 3)
|
|---|
| 21 | ** xyz double[3] geocentric vector (Note 4)
|
|---|
| 22 | **
|
|---|
| 23 | ** Returned:
|
|---|
| 24 | ** elong double longitude (radians, east +ve)
|
|---|
| 25 | ** phi double latitude (geodetic, radians)
|
|---|
| 26 | ** height double height above ellipsoid (geodetic, Note 4)
|
|---|
| 27 | **
|
|---|
| 28 | ** Returned (function value):
|
|---|
| 29 | ** int status: 0 = OK
|
|---|
| 30 | ** -1 = illegal f
|
|---|
| 31 | ** -2 = illegal a
|
|---|
| 32 | **
|
|---|
| 33 | ** Notes:
|
|---|
| 34 | **
|
|---|
| 35 | ** 1) This function is based on the GCONV2H Fortran subroutine by
|
|---|
| 36 | ** Toshio Fukushima (see reference).
|
|---|
| 37 | **
|
|---|
| 38 | ** 2) The equatorial radius, a, can be in any units, but meters is
|
|---|
| 39 | ** the conventional choice.
|
|---|
| 40 | **
|
|---|
| 41 | ** 3) The flattening, f, is (for the Earth) a value around 0.00335,
|
|---|
| 42 | ** i.e. around 1/298.
|
|---|
| 43 | **
|
|---|
| 44 | ** 4) The equatorial radius, a, and the geocentric vector, xyz,
|
|---|
| 45 | ** must be given in the same units, and determine the units of
|
|---|
| 46 | ** the returned height, height.
|
|---|
| 47 | **
|
|---|
| 48 | ** 5) If an error occurs (status < 0), elong, phi and height are
|
|---|
| 49 | ** unchanged.
|
|---|
| 50 | **
|
|---|
| 51 | ** 6) The inverse transformation is performed in the function
|
|---|
| 52 | ** iauGd2gce.
|
|---|
| 53 | **
|
|---|
| 54 | ** 7) The transformation for a standard ellipsoid (such as WGS84) can
|
|---|
| 55 | ** more conveniently be performed by calling iauGc2gd, which uses a
|
|---|
| 56 | ** numerical code to identify the required A and F values.
|
|---|
| 57 | **
|
|---|
| 58 | ** Reference:
|
|---|
| 59 | **
|
|---|
| 60 | ** Fukushima, T., "Transformation from Cartesian to geodetic
|
|---|
| 61 | ** coordinates accelerated by Halley's method", J.Geodesy (2006)
|
|---|
| 62 | ** 79: 689-693
|
|---|
| 63 | **
|
|---|
| 64 | ** This revision: 2014 November 7
|
|---|
| 65 | **
|
|---|
| 66 | ** SOFA release 2015-02-09
|
|---|
| 67 | **
|
|---|
| 68 | ** Copyright (C) 2015 IAU SOFA Board. See notes at end.
|
|---|
| 69 | */
|
|---|
| 70 | {
|
|---|
| 71 | double aeps2, e2, e4t, ec2, ec, b, x, y, z, p2, absz, p, s0, pn, zc,
|
|---|
| 72 | c0, c02, c03, s02, s03, a02, a0, a03, d0, f0, b0, s1,
|
|---|
| 73 | cc, s12, cc2;
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | /* ------------- */
|
|---|
| 77 | /* Preliminaries */
|
|---|
| 78 | /* ------------- */
|
|---|
| 79 |
|
|---|
| 80 | /* Validate ellipsoid parameters. */
|
|---|
| 81 | if ( f < 0.0 || f >= 1.0 ) return -1;
|
|---|
| 82 | if ( a <= 0.0 ) return -2;
|
|---|
| 83 |
|
|---|
| 84 | /* Functions of ellipsoid parameters (with further validation of f). */
|
|---|
| 85 | aeps2 = a*a * 1e-32;
|
|---|
| 86 | e2 = (2.0 - f) * f;
|
|---|
| 87 | e4t = e2*e2 * 1.5;
|
|---|
| 88 | ec2 = 1.0 - e2;
|
|---|
| 89 | if ( ec2 <= 0.0 ) return -1;
|
|---|
| 90 | ec = sqrt(ec2);
|
|---|
| 91 | b = a * ec;
|
|---|
| 92 |
|
|---|
| 93 | /* Cartesian components. */
|
|---|
| 94 | x = xyz[0];
|
|---|
| 95 | y = xyz[1];
|
|---|
| 96 | z = xyz[2];
|
|---|
| 97 |
|
|---|
| 98 | /* Distance from polar axis squared. */
|
|---|
| 99 | p2 = x*x + y*y;
|
|---|
| 100 |
|
|---|
| 101 | /* Longitude. */
|
|---|
| 102 | *elong = p2 > 0.0 ? atan2(y, x) : 0.0;
|
|---|
| 103 |
|
|---|
| 104 | /* Unsigned z-coordinate. */
|
|---|
| 105 | absz = fabs(z);
|
|---|
| 106 |
|
|---|
| 107 | /* Proceed unless polar case. */
|
|---|
| 108 | if ( p2 > aeps2 ) {
|
|---|
| 109 |
|
|---|
| 110 | /* Distance from polar axis. */
|
|---|
| 111 | p = sqrt(p2);
|
|---|
| 112 |
|
|---|
| 113 | /* Normalization. */
|
|---|
| 114 | s0 = absz / a;
|
|---|
| 115 | pn = p / a;
|
|---|
| 116 | zc = ec * s0;
|
|---|
| 117 |
|
|---|
| 118 | /* Prepare Newton correction factors. */
|
|---|
| 119 | c0 = ec * pn;
|
|---|
| 120 | c02 = c0 * c0;
|
|---|
| 121 | c03 = c02 * c0;
|
|---|
| 122 | s02 = s0 * s0;
|
|---|
| 123 | s03 = s02 * s0;
|
|---|
| 124 | a02 = c02 + s02;
|
|---|
| 125 | a0 = sqrt(a02);
|
|---|
| 126 | a03 = a02 * a0;
|
|---|
| 127 | d0 = zc*a03 + e2*s03;
|
|---|
| 128 | f0 = pn*a03 - e2*c03;
|
|---|
| 129 |
|
|---|
| 130 | /* Prepare Halley correction factor. */
|
|---|
| 131 | b0 = e4t * s02 * c02 * pn * (a0 - ec);
|
|---|
| 132 | s1 = d0*f0 - b0*s0;
|
|---|
| 133 | cc = ec * (f0*f0 - b0*c0);
|
|---|
| 134 |
|
|---|
| 135 | /* Evaluate latitude and height. */
|
|---|
| 136 | *phi = atan(s1/cc);
|
|---|
| 137 | s12 = s1 * s1;
|
|---|
| 138 | cc2 = cc * cc;
|
|---|
| 139 | *height = (p*cc + absz*s1 - a * sqrt(ec2*s12 + cc2)) /
|
|---|
| 140 | sqrt(s12 + cc2);
|
|---|
| 141 | } else {
|
|---|
| 142 |
|
|---|
| 143 | /* Exception: pole. */
|
|---|
| 144 | *phi = DPI / 2.0;
|
|---|
| 145 | *height = absz - b;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | /* Restore sign of latitude. */
|
|---|
| 149 | if ( z < 0 ) *phi = -*phi;
|
|---|
| 150 |
|
|---|
| 151 | /* OK status. */
|
|---|
| 152 | return 0;
|
|---|
| 153 |
|
|---|
| 154 | /*----------------------------------------------------------------------
|
|---|
| 155 | **
|
|---|
| 156 | ** Copyright (C) 2015
|
|---|
| 157 | ** Standards Of Fundamental Astronomy Board
|
|---|
| 158 | ** of the International Astronomical Union.
|
|---|
| 159 | **
|
|---|
| 160 | ** =====================
|
|---|
| 161 | ** SOFA Software License
|
|---|
| 162 | ** =====================
|
|---|
| 163 | **
|
|---|
| 164 | ** NOTICE TO USER:
|
|---|
| 165 | **
|
|---|
| 166 | ** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
|
|---|
| 167 | ** CONDITIONS WHICH APPLY TO ITS USE.
|
|---|
| 168 | **
|
|---|
| 169 | ** 1. The Software is owned by the IAU SOFA Board ("SOFA").
|
|---|
| 170 | **
|
|---|
| 171 | ** 2. Permission is granted to anyone to use the SOFA software for any
|
|---|
| 172 | ** purpose, including commercial applications, free of charge and
|
|---|
| 173 | ** without payment of royalties, subject to the conditions and
|
|---|
| 174 | ** restrictions listed below.
|
|---|
| 175 | **
|
|---|
| 176 | ** 3. You (the user) may copy and distribute SOFA source code to others,
|
|---|
| 177 | ** and use and adapt its code and algorithms in your own software,
|
|---|
| 178 | ** on a world-wide, royalty-free basis. That portion of your
|
|---|
| 179 | ** distribution that does not consist of intact and unchanged copies
|
|---|
| 180 | ** of SOFA source code files is a "derived work" that must comply
|
|---|
| 181 | ** with the following requirements:
|
|---|
| 182 | **
|
|---|
| 183 | ** a) Your work shall be marked or carry a statement that it
|
|---|
| 184 | ** (i) uses routines and computations derived by you from
|
|---|
| 185 | ** software provided by SOFA under license to you; and
|
|---|
| 186 | ** (ii) does not itself constitute software provided by and/or
|
|---|
| 187 | ** endorsed by SOFA.
|
|---|
| 188 | **
|
|---|
| 189 | ** b) The source code of your derived work must contain descriptions
|
|---|
| 190 | ** of how the derived work is based upon, contains and/or differs
|
|---|
| 191 | ** from the original SOFA software.
|
|---|
| 192 | **
|
|---|
| 193 | ** c) The names of all routines in your derived work shall not
|
|---|
| 194 | ** include the prefix "iau" or "sofa" or trivial modifications
|
|---|
| 195 | ** thereof such as changes of case.
|
|---|
| 196 | **
|
|---|
| 197 | ** d) The origin of the SOFA components of your derived work must
|
|---|
| 198 | ** not be misrepresented; you must not claim that you wrote the
|
|---|
| 199 | ** original software, nor file a patent application for SOFA
|
|---|
| 200 | ** software or algorithms embedded in the SOFA software.
|
|---|
| 201 | **
|
|---|
| 202 | ** e) These requirements must be reproduced intact in any source
|
|---|
| 203 | ** distribution and shall apply to anyone to whom you have
|
|---|
| 204 | ** granted a further right to modify the source code of your
|
|---|
| 205 | ** derived work.
|
|---|
| 206 | **
|
|---|
| 207 | ** Note that, as originally distributed, the SOFA software is
|
|---|
| 208 | ** intended to be a definitive implementation of the IAU standards,
|
|---|
| 209 | ** and consequently third-party modifications are discouraged. All
|
|---|
| 210 | ** variations, no matter how minor, must be explicitly marked as
|
|---|
| 211 | ** such, as explained above.
|
|---|
| 212 | **
|
|---|
| 213 | ** 4. You shall not cause the SOFA software to be brought into
|
|---|
| 214 | ** disrepute, either by misuse, or use for inappropriate tasks, or
|
|---|
| 215 | ** by inappropriate modification.
|
|---|
| 216 | **
|
|---|
| 217 | ** 5. The SOFA software is provided "as is" and SOFA makes no warranty
|
|---|
| 218 | ** as to its use or performance. SOFA does not and cannot warrant
|
|---|
| 219 | ** the performance or results which the user may obtain by using the
|
|---|
| 220 | ** SOFA software. SOFA makes no warranties, express or implied, as
|
|---|
| 221 | ** to non-infringement of third party rights, merchantability, or
|
|---|
| 222 | ** fitness for any particular purpose. In no event will SOFA be
|
|---|
| 223 | ** liable to the user for any consequential, incidental, or special
|
|---|
| 224 | ** damages, including any lost profits or lost savings, even if a
|
|---|
| 225 | ** SOFA representative has been advised of such damages, or for any
|
|---|
| 226 | ** claim by any third party.
|
|---|
| 227 | **
|
|---|
| 228 | ** 6. The provision of any version of the SOFA software under the terms
|
|---|
| 229 | ** and conditions specified herein does not imply that future
|
|---|
| 230 | ** versions will also be made available under the same terms and
|
|---|
| 231 | ** conditions.
|
|---|
| 232 | *
|
|---|
| 233 | ** In any published work or commercial product which uses the SOFA
|
|---|
| 234 | ** software directly, acknowledgement (see www.iausofa.org) is
|
|---|
| 235 | ** appreciated.
|
|---|
| 236 | **
|
|---|
| 237 | ** Correspondence concerning SOFA software should be addressed as
|
|---|
| 238 | ** follows:
|
|---|
| 239 | **
|
|---|
| 240 | ** By email: sofa@ukho.gov.uk
|
|---|
| 241 | ** By post: IAU SOFA Center
|
|---|
| 242 | ** HM Nautical Almanac Office
|
|---|
| 243 | ** UK Hydrographic Office
|
|---|
| 244 | ** Admiralty Way, Taunton
|
|---|
| 245 | ** Somerset, TA1 2DN
|
|---|
| 246 | ** United Kingdom
|
|---|
| 247 | **
|
|---|
| 248 | **--------------------------------------------------------------------*/
|
|---|
| 249 |
|
|---|
| 250 | }
|
|---|