Пример #1
0
void main( int argc, char **argv)
{
   FILE *ifile = fopen( "elp82.dat", "rb");
   double xyz[4], t;
   int i;
   const double prec = (argc == 1 ? 0 : atof( argv[1]));
   const double results_from_book[5][3] = {
             -361602.98536,    44996.99510,    -30696.65316,
             -363132.34248,    35863.65378,    -33196.00409,
             -371577.58161,    75271.14315,    -32227.94618,
             -373896.15893,   127406.79129,    -30037.79225,
             -346331.77361,   206365.40364,    -28502.11732 };
   if( !ifile)
      {
      printf( "elp82.dat not found\n");
      exit( -1);
      }

   for( i = 0; i < 5; i++)
      {
      t = 2469000.5 - 20000. * (double)i;
      compute_elp_xyz( ifile, (t - J2000) / 36525., prec, xyz);
      printf( "%.3lf: %15.5lf %15.5lf %15.5lf  %15.5lf\n", t,
                           xyz[0], xyz[1], xyz[2], xyz[3]);
      printf( "             %15.5lf %15.5lf %15.5lf\n",
                           results_from_book[i][0] - xyz[0],
                           results_from_book[i][1] - xyz[1],
                           results_from_book[i][2] - xyz[2] );
      }
   for( i = 2; i < argc; i++)
      {
      t = atof( argv[i]);
      compute_elp_xyz( ifile, (t - J2000) / 36525., 0., xyz);
      printf( "%.3lf: %15.5lf %15.5lf %15.5lf  %15.5lf\n", t,
                           xyz[0], xyz[1], xyz[2], xyz[3]);
      }
   fclose( ifile);
}
Пример #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);
}