cdm/src/main/java/ucar/nc2/dataset/conv/Cosmic1Convention.java
public double[] xyzell(double a, double b, double[] xstat) {


    double[] xstell = new double[3];
    double e2, s, rlam, zps, h, phi, n, hp, phip;
    int i, niter;

    e2 = (a * a - b * b) / (a * a);
    s = Math.sqrt(xstat[0] * xstat[0] + xstat[1] * xstat[1]);
    rlam = Math.atan2(xstat[1], xstat[0]);
    zps = xstat[2] / s;
    h = Math.sqrt(xstat[0] * xstat[0] + xstat[1] * xstat[1]
            + xstat[2] * xstat[2]) - a;
    phi = Math.atan(zps / (1.0 - e2 * a / (a + h)));

    niter = 0;
    for (i = 1; i <= 10000000; i++) {
      n = a / Math.sqrt(1.0 - e2 * Math.sin(phi) * Math.sin(phi));
      hp = h;
      phip = phi;
      h = s / Math.cos(phi) - n;
      phi = Math.atan(zps / (1.0 - e2 * n / (n + h)));
      niter = niter + 1;
      if ((Math.abs(phip - phi) <= 1.e-11)
              && (Math.abs(hp - h) <= 1.e-5)) {
        break;
      }
      if (niter >= 10) {
        phi = -999.0;
        rlam = -999.0;
        h = -999.0;
        break;
      }

    }

    xstell[0] = phi * 180 / 3.1415926;
    xstell[1] = rlam * 180 / 3.1415926;
    xstell[2] = h;

    return xstell;

  }
public double[] xyzell(double a, double b, double[] xstat) {


    double[] xstell = new double[3];
    double e2, s, rlam, zps, h, phi, n, hp, phip;
    int i, niter;

    e2 = (a * a - b * b) / (a * a);
    s = Math.sqrt(xstat[0] * xstat[0] + xstat[1] * xstat[1]);
    rlam = Math.atan2(xstat[1], xstat[0]);
    zps = xstat[2] / s;
    h = Math.sqrt(xstat[0] * xstat[0] + xstat[1] * xstat[1]
            + xstat[2] * xstat[2]) - a;
    phi = Math.atan(zps / (1.0 - e2 * a / (a + h)));

    niter = 0;
    for (i = 1; i <= 10000000; i++) {
      n = a / Math.sqrt(1.0 - e2 * Math.sin(phi) * Math.sin(phi));
      hp = h;
      phip = phi;
      h = s / Math.cos(phi) - n;
      phi = Math.atan(zps / (1.0 - e2 * n / (n + h)));
      niter = niter + 1;
      if ((Math.abs(phip - phi) <= 1.e-11)
              && (Math.abs(hp - h) <= 1.e-5)) {
        break;
      }
      if (niter >= 10) {
        phi = -999.0;
        rlam = -999.0;
        h = -999.0;
        break;
      }

    }

    xstell[0] = phi * 180 / 3.1415926;
    xstell[1] = rlam * 180 / 3.1415926;
    xstell[2] = h;

    return xstell;

  }
public double [ ] xyzell ( double a , double b , double [ ] xstat ) { double [ ] xstell = new double [ 3 ] ; double e2 , s , rlam , zps , h , phi , n , hp , phip ; int i , niter ; e2 = ( a * a - b * b ) / ( a * a ) ; s = Math . sqrt ( xstat [ 0 ] * xstat [ 0 ] + xstat [ 1 ] * xstat [ 1 ] ) ; rlam = Math . atan2 ( xstat [ 1 ] , xstat [ 0 ] ) ; zps = xstat [ 2 ] / s ; h = Math . sqrt ( xstat [ 0 ] * xstat [ 0 ] + xstat [ 1 ] * xstat [ 1 ] + xstat [ 2 ] * xstat [ 2 ] ) - a ; phi = Math . atan ( zps / ( 1.0 - e2 * a / ( a + h ) ) ) ; niter = 0 ; for ( i = 1 ; i <= 10000000 ; i ++ ) { n = a / Math . sqrt ( 1.0 - e2 * Math . sin ( phi ) * Math . sin ( phi ) ) ; hp = h ; phip = phi ; h = s / Math . cos ( phi ) - n ; phi = Math . atan ( zps / ( 1.0 - e2 * n / ( n + h ) ) ) ; niter = niter + 1 ; if ( ( Math . abs ( phip - phi ) <= 1.e-11 ) && ( Math . abs ( hp - h ) <= 1.e-5 ) ) { break ; } if ( niter >= 10 ) { phi = - 999.0 ; rlam = - 999.0 ; h = - 999.0 ; break ; } } xstell [ 0 ] = phi * 180 / 3.1415926 ; xstell [ 1 ] = rlam * 180 / 3.1415926 ; xstell [ 2 ] = h ; return xstell ; }
NAME       :  XYZELL
<p/>
CALL XYZELL(A,B,XSTAT,XSTELL)
<p/>
PURPOSE    :  COMPUTATION OF ELLIPSOIDAL COORDINATES "XSTELL"
GIVEN THE CARTESIAN COORDINATES "XSTAT"
<p/>
PARAMETERS :
IN :  A   : SEMI-MAJOR AXIS OF THE REFERENCE    R*8
ELLIPSOID IN METERS
B   : SEMI-MINOR AXIS OF THE REFERENCE    R*8
ELLIPSOID IN METERS
DXELL(3): TRANSLATION COMPONENTS FROM THE    R*8
ORIGIN OF THE CART. COORD. SYSTEM
(X,Y,Z) TO THE CENTER OF THE REF.
ELLIPSOID (IN METRES)
SCELL  : SCALE FACTOR BETWEEN REF. ELLIPSOID R*8
AND WGS-84
XSTAT(3): CARTESIAN COORDINATES (M)          R*8
OUT :  XSTELL(3): ELLIPSOIDAL COORDINATES           R*8
XSTELL(1): ELL. LATITUDE (RADIAN)
XSTELL(2): ELL. LONGITUDE (RADIAN)
XSTELL(3): ELL. HEIGHT (M)
<p/>
SR CALLED  :  DMLMTV
<p/>
REMARKS    :  ---
<p/>
AUTHOR     :  M. ROTHACHER
<p/>
VERSION    :  3.4  (JAN 93)
<p/>
CREATED    :  87/11/03 12:32        LAST MODIFIED :  88/11/21 17:36
<p/>
COPYRIGHT  :  ASTRONOMICAL INSTITUTE
1987      UNIVERSITY OF BERNE
SWITZERLAND

@param a     _more_
@param b     _more_
@param xstat _more_
@return _more_
NAME : XYZELL <p / > CALL XYZELL ( A B XSTAT XSTELL ) <p / > PURPOSE : COMPUTATION OF ELLIPSOIDAL COORDINATES XSTELL GIVEN THE CARTESIAN COORDINATES XSTAT <p / > PARAMETERS : IN : A : SEMI - MAJOR AXIS OF THE REFERENCE R * 8 ELLIPSOID IN METERS B : SEMI - MINOR AXIS OF THE REFERENCE R * 8 ELLIPSOID IN METERS DXELL ( 3 ) : TRANSLATION COMPONENTS FROM THE R * 8 ORIGIN OF THE CART . COORD . SYSTEM ( X Y Z ) TO THE CENTER OF THE REF . ELLIPSOID ( IN METRES ) SCELL : SCALE FACTOR BETWEEN REF . ELLIPSOID R * 8 AND WGS - 84 XSTAT ( 3 ) : CARTESIAN COORDINATES ( M ) R * 8 OUT : XSTELL ( 3 ) : ELLIPSOIDAL COORDINATES R * 8 XSTELL ( 1 ) : ELL . LATITUDE ( RADIAN ) XSTELL ( 2 ) : ELL . LONGITUDE ( RADIAN ) XSTELL ( 3 ) : ELL . HEIGHT ( M ) <p / > SR CALLED : DMLMTV <p / > REMARKS : --- <p / > AUTHOR : M . ROTHACHER <p / > VERSION : 3 . 4 ( JAN 93 ) <p / > CREATED : 87 / 11 / 03 12 : 32 LAST MODIFIED : 88 / 11 / 21 17 : 36 <p / > COPYRIGHT : ASTRONOMICAL INSTITUTE 1987 UNIVERSITY OF BERNE SWITZERLAND