Exemplo n.º 1
0
int main( int argc, char **argv)
{
   double state_vect[6];
   double t0 = atof( argv[2]), r;
   void *p;
   FILE *ifile;

   if( argc < 3)
      {
      printf( "You must supply a planet index (1=Mercury...8=Neptune)\n");
      printf( "and a JD as command-line arguments.\n");
      return( -3);
      }
   ifile = fopen( "ps_1996.dat", "rb");
   if( !ifile)
      {
      printf( "ps_1996.dat not loaded\n");
      return( -2);
      }
   p = load_ps1996_series( ifile, t0, atoi( argv[1]));
   fclose( ifile);
   if( !p)
      {
      printf( "Outside bounds of series\n");
      return( -1);
      }
   printf( "Series loaded\n");
   get_ps1996_position( t0, p, state_vect, 1);
   free( p);
   r = state_vect[0] * state_vect[0] + state_vect[1] * state_vect[1] +
                        state_vect[2] * state_vect[2];

   printf( "%.9lf %.9lf %.9lf  %.9lf\n", state_vect[0], state_vect[1],
            state_vect[2], sqrt( r));
   printf( "%.9lf %.9lf %.9lf\n", state_vect[3], state_vect[4],
            state_vect[5]);
   return( 0);
}
Exemplo n.º 2
0
static int planet_posn_raw( int planet_no, const double jd,
                            double *vect_2000)
{
   static void *ps_1996_data[10];
   const int jpl_center = 11;         /* default to heliocentric */
   int i, rval = 0;
   static const char *jpl_filename = NULL;
   static void *jpl_eph = NULL;
   const int bc405_start = 100;
   const int calc_vel = (planet_no & PLANET_POSN_VELOCITY_FLAG) ? 1 : 0;

   planet_no &= ~PLANET_POSN_VELOCITY_FLAG;
   if( !planet_no)            /* the sun */
      {
      vect_2000[0] = vect_2000[1] = vect_2000[2] = 0.;
      if( !jd && jpl_eph)       /* return version data: */
         {
         vect_2000[0] = (double)jpl_get_long( jpl_eph, JPL_EPHEM_EPHEMERIS_VERSION);
         vect_2000[1] = jpl_get_double( jpl_eph, JPL_EPHEM_START_JD);
         vect_2000[2] = jpl_get_double( jpl_eph, JPL_EPHEM_END_JD);
         }
      return( 0);
      }

   if( planet_no >= bc405_start && planet_no < bc405_start + 300)
      {
      double temp_loc[4];

      rval = asteroid_position_raw( planet_no - bc405_start, jd, temp_loc);
      if( debug_level > 8)
         debug_printf( "JD %f, minor planet %d: (%f %f %f)\n",
                     jd, planet_no, temp_loc[0], temp_loc[1], temp_loc[2]);
      memcpy( vect_2000, temp_loc, 3 * sizeof( double));
      return( rval);
      }

   if( !jpl_filename)
      {
      FILE *ifile;

#if defined (_WIN32) || defined( __WATCOMC__)
      jpl_filename = get_environment_ptr( "JPL_FILENAME");
#else
      jpl_filename = get_environment_ptr( "LINUX_JPL_FILENAME");
#endif
      if( *jpl_filename)
         jpl_eph = jpl_init_ephemeris( jpl_filename, NULL, NULL);
      if( !jpl_eph)
         if( (ifile = fopen_ext( "jpl_eph.txt", "fcrb")) != NULL)
            {
            char buff[100];

            while( !jpl_eph && fgets_trimmed( buff, sizeof( buff), ifile))
               if( *buff && *buff != ';')
                  {
                  jpl_eph = jpl_init_ephemeris( buff, NULL, NULL);
                  if( !jpl_eph)
                     {
                     char tname[255];

                     make_config_dir_name( tname, buff);
                     jpl_eph = jpl_init_ephemeris( tname, NULL, NULL);
                     }
                  }
            if( debug_level)
               debug_printf( "Ephemeris file %s\n", buff);
            fclose( ifile);
            }
      if( debug_level && jpl_eph)
         {
         debug_printf( "\nEphemeris time span years %.3f to %.3f\n",
               (jpl_get_double( jpl_eph, JPL_EPHEM_START_JD) - J0) / 365.25,
               (jpl_get_double( jpl_eph, JPL_EPHEM_END_JD)   - J0) / 365.25);
         debug_printf( "Ephemeris version %ld\n", jpl_get_long( jpl_eph, JPL_EPHEM_EPHEMERIS_VERSION));
         debug_printf( "Kernel size %ld, record size %ld, swap_bytes %ld\n",
               jpl_get_long( jpl_eph, JPL_EPHEM_KERNEL_SIZE),
               jpl_get_long( jpl_eph, JPL_EPHEM_KERNEL_RECORD_SIZE),
               jpl_get_long( jpl_eph, JPL_EPHEM_KERNEL_SWAP_BYTES));
         debug_printf( "ncon = %ld AU=%f emrat = %f\n",
               jpl_get_long( jpl_eph, JPL_EPHEM_N_CONSTANTS),
               jpl_get_double( jpl_eph, JPL_EPHEM_AU_IN_KM),
               jpl_get_double( jpl_eph, JPL_EPHEM_EARTH_MOON_RATIO));
         }
      }

   if( jpl_eph)
      {
      double state[6];            /* DE gives both posn & velocity */
      int failure_code;

      if( planet_no < 0)          /* flag to unload everything */
         {
         jpl_close_ephemeris( jpl_eph);
         jpl_eph = NULL;
         jpl_filename = NULL;
         return( 0);
         }
      else if( planet_no == 10)
         failure_code = jpl_pleph( jpl_eph, jd, 10, 3, state, calc_vel);
      else
         failure_code = jpl_pleph( jpl_eph, jd,
              (planet_no == 3) ? 13 : planet_no, jpl_center, state, calc_vel);
      if( !failure_code)         /* we're done */
         {
         if( debug_level > 8)
            debug_printf( "JD %f, planet %d: (%f %f %f)\n",
                     jd, planet_no, state[0], state[1], state[2]);
         equatorial_to_ecliptic( state);
         memcpy( vect_2000, state + calc_vel, 3 * sizeof( double));
         return( 0);
         }
      else
         if( debug_level)
            debug_printf( "Failed: JD %f, planet %d, code %d\n",
                           jd, planet_no, failure_code);
      }

   if( planet_no == 10)        /* the moon */
      {
      double tloc[4];

      if( !compute_elp_xyz( NULL, (jd - J2000) / 36525., 0., tloc))
         for( i = 0; i < 3; i++)
            vect_2000[i] = tloc[i] / AU_IN_KM;
      else
         {
         static int first_time = 1;

         rval = -3;
         if( first_time)
            generic_message_box( get_find_orb_text( 2019), "o");
         first_time = 0;
         compute_rough_planet_loc( (jd - J2000) / 36525., 10, vect_2000);
         }
      return( rval);
      }

   if( planet_no < 0)          /* flag to unload everything */
      {
      for( i = 0; i < 10; i++)
         if( ps_1996_data[i])
            {
            unload_ps1996_series( ps_1996_data[i]);
            ps_1996_data[i] = NULL;
            }
      return( 0);
      }

   if( !ps_1996_data[planet_no])
      ps_1996_data[planet_no] = load_ps1996_series( NULL, jd, planet_no);

   if( !ps_1996_data[planet_no])
      rval = -1;
   else if( get_ps1996_position( jd, ps_1996_data[planet_no], vect_2000, 0))
      {
      unload_ps1996_series( ps_1996_data[planet_no]);
      ps_1996_data[planet_no] = load_ps1996_series( NULL, jd, planet_no);
      if( !ps_1996_data[planet_no])
         rval = -2;
      else if( get_ps1996_position( jd, ps_1996_data[planet_no], vect_2000, 0))
         rval = -3;
      }

   if( !rval)
      equatorial_to_ecliptic( vect_2000);
   else
      {
      static int first_time = 1;

      if( first_time)
         {
         generic_message_box( get_find_orb_text( 2020), "o");
         debug_printf( "Loading ps_1996: rval %d, planet %d, JD %f\n",
                  rval, planet_no, jd);
         }
      first_time = 0;
      if( planet_no > 0 && planet_no < 9)
         compute_rough_planet_loc( (jd - J2000) / 36525., planet_no, vect_2000);
      }

   return( rval);
}