Esempio n. 1
0
/*****************************************************************************
**           jpl_pleph(ephem,et,ntar,ncent,rrd,calc_velocity)              **
******************************************************************************
**                                                                          **
**    This subroutine reads the jpl planetary ephemeris                     **
**    and gives the position and velocity of the point 'ntarg'              **
**    with respect to 'ncent'.                                              **
**                                                                          **
**    Calling sequence parameters:                                          **
**                                                                          **
**      et = (double) julian ephemeris date at which interpolation          **
**           is wanted.                                                     **
**                                                                          **
**    ntarg = integer number of 'target' point.                             **
**                                                                          **
**    ncent = integer number of center point.                               **
**                                                                          **
**    The numbering convention for 'ntarg' and 'ncent' is:                  **
**                                                                          **
**            1 = mercury           8 = neptune                             **
**            2 = venus             9 = pluto                               **
**            3 = earth            10 = moon                                **
**            4 = mars             11 = sun                                 **
**            5 = jupiter          12 = solar-system barycenter             **
**            6 = saturn           13 = earth-moon barycenter               **
**            7 = uranus           14 = nutations (longitude and obliq)     **
**                                 15 = librations, if on eph. file         **
**                                 16 = lunar mantle omega_x,omega_y,omega_z**
**                                 17 = TT-TDB, if on eph. file             **
**                                                                          **
**            (If nutations are wanted, set ntarg = 14.                     **
**             For librations, set ntarg = 15. set ncent= 0.                **
**             For TT-TDB,  set ntarg = 17.  I've not actually              **
**             seen an ntarg = 16 case yet.)                                **
**                                                                          **
**     rrd = output 6-element, double array of position and velocity        **
**           of point 'ntarg' relative to 'ncent'. The units are au and     **
**           au/day. For librations the units are radians and radians       **
**           per day. In the case of nutations the first four words of      **
**           rrd will be set to nutations and rates, having units of        **
**           radians and radians/day.                                       **
**                                                                          **
**           The option is available to have the units in km and km/sec.    **
**           for this, set km=TRUE at the beginning of the program.         **
**                                                                          **
**     calc_velocity = integer flag;  if nonzero,  velocities will be       **
**           computed,  otherwise not.                                      **
**                                                                          **
*****************************************************************************/
int DLL_FUNC jpl_pleph(void *ephem, const double et, const int ntarg,
                      const int ncent, double rrd[], const int calc_velocity)
{
    struct jpl_eph_data *eph = (struct jpl_eph_data *)ephem;
    double pv[13][6];/* pv is the position/velocity array
                             NUMBERED FROM ZERO: 0=Mercury,1=Venus,...
                             8=Pluto,9=Moon,10=Sun,11=SSBary,12=EMBary
                             First 10 elements (0-9) are affected by
                             jpl_state(), all are adjusted here.         */


    int rval = 0;
    const int list_val = (calc_velocity ? 2 : 1);
    unsigned i;
    int list[14];    /* list is a vector denoting, for which "body"
                            ephemeris values should be calculated by
                            jpl_state():  0=Mercury,1=Venus,2=EMBary,...,
                            8=Pluto,  9=geocentric Moon, 10=nutations in
                            long. & obliq.  11= lunar librations;
                            12 = TT-TDB, 13=lunar mantle omegas */

    for(i = 0; i < 6; ++i) rrd[i] = 0.0;

    if(ntarg == ncent) return(0);

    for(i = 0; i < sizeof(list) / sizeof(list[0]); i++)
      list[i] = 0;

         /* Because of the whacko indexing in JPL ephemerides,  we need */
         /* to work out way through the following indexing schemes :   */
         /* ntarg       ipt         list     */
         /*  14          11          10      Nutations */
         /*  15          12          11      Librations */
         /*  16          13          12      Lunar mantle angular vel */
         /*  17          14          13      TT - TDB */

    for(i = 0; i < 4; i++)
      if(ntarg == (int)i + 14)
      {
        if(eph->ipt[i + 11][1] > 0) /* quantity is in ephemeris */
        {
          list[i + 10] = list_val;
          rval = jpl_state(ephem, et, list, pv, rrd, 0);
        }
        else          /*  quantity doesn't exist in the ephemeris file  */
          rval = JPL_EPH_QUANTITY_NOT_IN_EPHEMERIS;
        return(rval);
      }
    if(ntarg > 13 || ncent > 13 || ntarg < 1 || ncent < 1)
      return(JPL_EPH_INVALID_INDEX);

/*  force barycentric output by 'state'     */

/*  set up proper entries in 'list' array for state call     */

    for(i = 0; i < 2; i++) /* list[] IS NUMBERED FROM ZERO ! */
    {
      const unsigned k = (i ? ncent : ntarg) - 1;

      if(k <= 9) list[k] = list_val;   /* Major planets */
      if(k == 9) list[2] = list_val;   /* for moon,  earth state is needed */
      if(k == 2) list[9] = list_val;   /* for earth,  moon state is needed */
      if(k == 12) list[2] = list_val;  /* EMBary state additionally */
    }

  /*   make call to state   */
   rval = jpl_state(eph, et, list, pv, rrd, 1);
   /* Solar System barycentric Sun state goes to pv[10][] */
   if(ntarg == 11 || ncent == 11)
      for(i = 0; i < 6; i++)
         pv[10][i] = eph->pvsun[i];

   /* Solar System Barycenter coordinates & velocities equal to zero */
   if(ntarg == 12 || ncent == 12)
      for(i = 0; i < 6; i++)
         pv[11][i] = 0.0;

   /* Solar System barycentric EMBary state:  */
   if(ntarg == 13 || ncent == 13)
      for(i = 0; i < 6; i++)
         pv[12][i] = pv[2][i];

   /* if moon from earth or earth from moon ..... */
   if((ntarg*ncent) == 30 && (ntarg+ncent) == 13)
      for(i = 0; i < 6; ++i) pv[2][i]=0.0;
   else
      {
      if(list[2])           /* calculate earth state from EMBary */
         for(i = 0; i < list[2] * 3u; ++i)
            pv[2][i] -= pv[9][i]/(1.0+eph->emrat);

      if(list[9]) /* calculate Solar System barycentric moon state */
         for(i = 0; i < list[9] * 3u; ++i)
            pv[9][i] += pv[2][i];
      }

   for(i = 0; i < list_val * 3u; ++i)
      rrd[i] = pv[ntarg-1][i] - pv[ncent-1][i];

   return(rval);
}
Esempio n. 2
0
/*****************************************************************************
**           jpl_pleph( ephem,et,ntar,ncent,rrd,calc_velocity)              **
******************************************************************************
**                                                                          **
**    This subroutine reads the jpl planetary ephemeris                     **
**    and gives the position and velocity of the point 'ntarg'              **
**    with respect to 'ncent'.                                              **
**                                                                          **
**    Calling sequence parameters:                                          **
**                                                                          **
**      et = (double) julian ephemeris date at which interpolation          **
**           is wanted.                                                     **
**                                                                          **
**    ntarg = integer number of 'target' point.                             **
**                                                                          **
**    ncent = integer number of center point.                               **
**                                                                          **
**    The numbering convention for 'ntarg' and 'ncent' is:                  **
**                                                                          **
**            1 = mercury           8 = neptune                             **
**            2 = venus             9 = pluto                               **
**            3 = earth            10 = moon                                **
**            4 = mars             11 = sun                                 **
**            5 = jupiter          12 = solar-system barycenter             **
**            6 = saturn           13 = earth-moon barycenter               **
**            7 = uranus           14 = nutations (longitude and obliq)     **
**                                 15 = librations, if on eph. file         **
**                                                                          **
**            (If nutations are wanted, set ntarg = 14.                     **
**             For librations, set ntarg = 15. set ncent= 0)                **
**                                                                          **
**     rrd = output 6-element, double array of position and velocity        **
**           of point 'ntarg' relative to 'ncent'. The units are au and     **
**           au/day. For librations the units are radians and radians       **
**           per day. In the case of nutations the first four words of      **
**           rrd will be set to nutations and rates, having units of        **
**           radians and radians/day.                                       **
**                                                                          **
**           The option is available to have the units in km and km/sec.    **
**           for this, set km=TRUE at the begining of the program.          **
**                                                                          **
**     calc_velocity = integer flag;  if nonzero,  velocities will be       **
**           computed,  otherwise not.                                      **
**                                                                          **
*****************************************************************************/
int DLL_FUNC jpl_pleph( void *ephem, const double et[2], const int ntarg,
                        const int ncent, double rrd[], const int calc_velocity)
{
    struct jpl_eph_data *eph = (struct jpl_eph_data *)ephem;
    double pv[13][6];/* pv is the position/velocity array
                             NUMBERED FROM ZERO: 0=Mercury,1=Venus,...
                             8=Pluto,9=Moon,10=Sun,11=SSBary,12=EMBary
                             First 10 elements (0-9) are affected by
                             jpl_state(), all are adjusted here.         */


    int rval = 0, list_val = (calc_velocity ? 2 : 1);
    int i, k, list[12];    /* list is a vector denoting, for which "body"
                            ephemeris values should be calculated by
                            jpl_state():  0=Mercury,1=Venus,2=EMBary,...,
                            8=Pluto,  9=geocentric Moon, 10=nutations in
                            long. & obliq.  11= lunar librations  */

    for( i = 0; i < 6; ++i) rrd[i] = 0.0;

    if( ntarg == ncent) return( 0);

    for( i = 0; i < 12; i++) list[i] = 0;

    /* check for nutation call */

    if( ntarg == 14)
    {
        if( eph->ipt[11][1] > 0) /* there is nutation on ephemeris */
        {
            list[10] = list_val;
            if( jpl_state( ephem, et, list, pv, rrd, 0))
                rval = -1;
        }
        else          /*  no nutations on the ephemeris file  */
            rval = -2;
        return( rval);
    }

    /*  check for librations   */

    if( ntarg == 15)
    {
        if( eph->ipt[12][1] > 0) /* there are librations on ephemeris file */
        {
            list[11] = list_val;
            if( jpl_state( eph, et, list, pv, rrd, 0))
                rval = -3;
            for( i = 0; i < 6; ++i)
                rrd[i] = pv[10][i]; /* librations */
        }
        else          /*  no librations on the ephemeris file  */
            rval = -4;
        return( rval);
    }

    /*  force barycentric output by 'state'     */

    /*  set up proper entries in 'list' array for state call     */

    for( i = 0; i < 2; i++) /* list[] IS NUMBERED FROM ZERO ! */
    {
        k = ntarg-1;
        if( i == 1) k=ncent-1;            /* same for ntarg & ncent */
        if( k <= 9) list[k] = list_val;   /* Major planets */
        if( k == 9) list[2] = list_val;   /* for moon,  earth state is needed */
        if( k == 2) list[9] = list_val;   /* for earth,  moon state is needed */
        if( k == 12) list[2] = list_val;  /* EMBary state additionaly */
    }

    /*   make call to state   */

    if( jpl_state( eph, et, list, pv, rrd, 1))
        rval = -5;
    /* Solar System barycentric Sun state goes to pv[10][] */
    if( ntarg == 11 || ncent == 11)
        for( i = 0; i < 6; i++)
            pv[10][i] = eph->pvsun[i];

    /* Solar System Barycenter coordinates & velocities equal to zero */
    if( ntarg == 12 || ncent == 12)
        for( i = 0; i < 6; i++)
            pv[11][i] = 0.0;

    /* Solar System barycentric EMBary state:  */
    if( ntarg == 13 || ncent == 13)
        for( i = 0; i < 6; i++)
            pv[12][i] = pv[2][i];

    /* if moon from earth or earth from moon ..... */
    if( (ntarg*ncent) == 30 && (ntarg+ncent) == 13)
        for( i = 0; i < 6; ++i) pv[2][i]=0.0;
    else
    {
        if( list[2])           /* calculate earth state from EMBary */
            for( i = 0; i < list[2] * 3; ++i)
                pv[2][i] -= pv[9][i]/(1.0+eph->emrat);

        if(list[9]) /* calculate Solar System barycentric moon state */
            for( i = 0; i < list[9] * 3; ++i)
                pv[9][i] += pv[2][i];
    }

    for( i = 0; i < list_val * 3; ++i)
        rrd[i] = pv[ntarg-1][i] - pv[ncent-1][i];

    return( rval);
}