public static SphericalPositionVelocity jauPv2s(double pv[][])
    {
       double x, y, z, xd, yd, zd, rxy2, rxy, r2, rtrue, rw, xyp;
       double theta, phi, r, td, pd, rd;

    /* Components of position/velocity vector. */
       x  = pv[0][0];
       y  = pv[0][1];
       z  = pv[0][2];
       xd = pv[1][0];
       yd = pv[1][1];
       zd = pv[1][2];

    /* Component of r in XY plane squared. */
       rxy2 = x*x + y*y;

    /* Modulus squared. */
       r2 = rxy2 + z*z;

    /* Modulus. */
       rtrue = sqrt(r2);

    /* If null vector, move the origin along the direction of movement. */
       rw = rtrue;
       if (rtrue == 0.0) {
           x = xd;
           y = yd;
           z = zd;
           rxy2 = x*x + y*y;
           r2 = rxy2 + z*z;
           rw = sqrt(r2);
       }

    /* Position and velocity in spherical coordinates. */
       rxy = sqrt(rxy2);
       xyp = x*xd + y*yd;
       if (rxy2 != 0.0) {
           theta = atan2(y, x);
           phi = atan2(z, rxy);
           td = (x*yd - y*xd) / rxy2;
           pd = (zd*rxy2 - z*xyp) / (r2*rxy);
       } else {
           theta = 0.0;
           phi = (z != 0.0) ? atan2(z, rxy) : 0.0;
           td = 0.0;
           pd = 0.0;
       }
       r = rtrue;
       rd = (rw != 0.0) ? (xyp + z*zd) / rw : 0.0;

       return new SphericalPositionVelocity(theta, phi, r, td, pd, rd);

        }