Esempio n. 1
0
void DLL_FUNC write_elements_in_tle_format( char *buff, const tle_t *tle)
{
   long year = (long)( tle->epoch - J1900) / 365 + 1;
   double day_of_year;
   char *line2;

   do
      {
      double start_of_year;

      year--;
      start_of_year = J1900 + (double)year * 365. + (double)((year - 1) / 4);
      day_of_year = tle->epoch - start_of_year;
      }
      while( day_of_year < 1.);
   sprintf( buff,
/*                                     xndt2o    xndd6o   bstar  eph bull */
           "1 %05d%c %-8s %02ld%12.8f -.000hit00 +00000-0 +00000-0 %c %4dZ\n",
           tle->norad_number, tle->classification, tle->intl_desig,
           year % 100L, day_of_year,
           tle->ephemeris_type, tle->bulletin_number);
   if( buff[20] == ' ')       /* fill in leading zeroes for day of year */
      buff[20] = '0';
   if( buff[21] == ' ')
      buff[21] = '0';
   if( tle->ephemeris_type != 'H')     /* "normal",  standard TLEs */
      {
      double deriv_mean_motion = tle->xndt2o * MINUTES_PER_DAY_SQUARED / (2. * PI);
      if( deriv_mean_motion >= 0)
         buff[33] = ' ';
      deriv_mean_motion = fabs( deriv_mean_motion * 100000000.) + .5;
      sprintf( buff + 35, "%08ld", (long)deriv_mean_motion);
      buff[43] = ' ';
      put_sci( buff + 44, tle->xndd6o * MINUTES_PER_DAY_CUBED / (2. * PI));
      put_sci( buff + 53, tle->bstar / AE);
      }
   else
      {
      size_t i;
      const double *posn = &tle->xincl;

      for( i = 0; i < 3; i++)
         set_high_value( buff + 33 + i * 10, posn[i]);
      buff[62] = 'H';
      }
   add_tle_checksum_data( buff);
   line2 = buff + strlen( buff);
   sprintf( line2, "2 %05d ", tle->norad_number);
   if( tle->ephemeris_type != 'H')     /* "normal",  standard TLEs */
      sprintf( line2 + 8, "%08.4f %08.4f %07ld %08.4f %08.4f %011.8f",
           zero_to_two_pi( tle->xincl) * 180. / PI,
           zero_to_two_pi( tle->xnodeo) * 180. / PI,
           (long)( tle->eo * 10000000. + .5),
           zero_to_two_pi( tle->omegao) * 180. / PI,
           zero_to_two_pi( tle->xmo) * 180. / PI,
           tle->xno * MINUTES_PER_DAY / (2. * PI));
   else
      {
      size_t i;
      const double *vel = &tle->xincl + 3;

      memset( line2 + 8, ' ', 25);     /* reserved for future use */
      for( i = 0; i < 3; i++)
         set_high_value( line2 + 33 + i * 10, vel[i] * 1e+4);
      }
   sprintf( line2 + 63, "%5dZ\n", tle->revolution_number);
   add_tle_checksum_data( line2);
}
Esempio n. 2
0
int DLL_FUNC elements_in_mpc_format( char *obuff, const ELEMENTS *elem,
                  const char *obj_id, const int is_cometary, const int format)
{
   const char *nineteen_blank_spaces = "                   ";
   double p_vect[3], q_vect[3];
   double dday;
   int month, i;
   long year;
   double perihelion_dist = elem->major_axis * (1. - elem->ecc);
   const double asc_node = zero_to_two_pi( elem->asc_node);
   const double arg_per = zero_to_two_pi( elem->arg_per);
   static const double planet_mass[11] = { 1.,
         1.660136795271931e-007,                /* mercury */
         2.447838339664545e-006,                /* venus */
         3.003489596331057e-006,                /* Earth */
         3.227151445053866e-007,                /* Mars */
         0.0009547919384243268,                 /* Jupiter */
         0.0002858859806661309,                 /* saturn */
         4.366244043351564e-005,                /* Uranus */
         5.151389020466116e-005,                /* Neptune */
         7.396449704142013e-009,                /* Pluto */
         3.003489596331057e-006 / EARTH_MOON_RATIO}; /* Moon */
   static const char *perinames[11] = {
            "helion", "mercury", "venus", "gee", "mars", "jove",
            "saturn", "uranus", "neptune", "pluto", "lune" };
   const int precision = (format & SHOWELEM_PRECISION_MASK);
   int n_lines = 0, n_digits_to_show;
   char *tptr;

   FSTRCPY( obuff, obj_id);
   obuff += strlen( obuff) + 1;
   n_lines++;
   if( elem->perih_time > 2. && elem->perih_time < 3000000.)
      {
      const char *format_string = "   Peri%s %ld %s %.6lf TT";

      dday = decimal_day_to_dmy( elem->perih_time, &year, &month,
                                             CALENDAR_JULIAN_GREGORIAN);
      sprintf( obuff, format_string, perinames[elem->central_obj], year,
              set_month_name( month, NULL), dday);
      if( format & SHOWELEM_PERIH_TIME_MASK)
         {
         char hhmmss[20];

         full_ctime( hhmmss, elem->perih_time,
                        FULL_CTIME_TIME_ONLY | CALENDAR_JULIAN_GREGORIAN);
         sprintf( obuff + strlen( obuff), " = %s (JD %.6lf)",
                               hhmmss, elem->perih_time);
         }
      obuff += strlen( obuff) + 1;
      n_lines++;
      }

   dday = decimal_day_to_dmy( elem->epoch, &year, &month,
                                             CALENDAR_JULIAN_GREGORIAN);
   sprintf( obuff, "Epoch %4ld %s %9.6lf TT = JDT %.6lf", year,
              set_month_name( month, NULL), dday + 1.e-7, elem->epoch + 1.e-7);
                     /* lop off trailing zeroes after JD...: */
   for( i = 0; i < 5 && obuff[strlen( obuff) - i - 1] == '0'; i++)
      ;
   obuff[strlen( obuff) - i] = '\0';
                     /* ...and similar zeroes after the day: */
   tptr = strstr( obuff, " TT =") - i;
   memmove( tptr, tptr + i, strlen( tptr) + 1);

   obuff += strlen( obuff) + 1;
   n_lines++;
   n_digits_to_show = (precision > 10 ? precision : 10);
   if( is_cometary || elem->ecc >= 1.)
      {
      *obuff = 'q';
      show_formatted_dist( obuff + 1, perihelion_dist, precision);
      for( i = strlen( obuff); i < n_digits_to_show + 6; i++)
         obuff[i] = ' ';
      obuff[n_digits_to_show + 6] = '\0';
      }
   else
      {
      const double mean_anomaly = zero_to_two_pi( elem->mean_anomaly);

      sprintf( obuff, "M%20.15lf", mean_anomaly * 180. / PI);
      lop_digits( obuff + 6, precision);
      }
   obuff += strlen( obuff);
   strcpy( obuff, "    (2000.0)");
   if( !(format & SHOWELEM_OMIT_PQ_MASK))
      strcat( obuff, "            P               Q");
   obuff += strlen( obuff) + 1;
   n_lines++;

   normal_vect( p_vect, elem->perih_vec);
   normal_vect( q_vect, elem->sideways);
   if( is_cometary || elem->ecc >= 1.)
      {
      if( elem->abs_mag)
         {
         const char *output_format;

         if( elem->is_asteroid)
            output_format = "H%7.1lf  G %4.2lf   ";
         else
            output_format = "M(T)%5.1lf  K%5.1lf  ";
         sprintf( obuff,  output_format, elem->abs_mag + .05,
                                         elem->slope_param);
         if( !elem->is_asteroid)
            if( format & SHOWELEM_COMET_MAGS_NUCLEAR)
               obuff[2] = 'N';
         }
      else
         strcpy( obuff, nineteen_blank_spaces);
      for( i = 19; i < n_digits_to_show + 9; i++)
         obuff[i] = ' ';
      obuff[i] = '\0';
      }
   else
      {
      sprintf( obuff, "n%*.*lf", n_digits_to_show + 8, n_digits_to_show + 3,
                              (180 / PI) / elem->t0);
      lop_digits( obuff + 9, precision);
      }
   obuff += strlen( obuff);

   sprintf( obuff, "Peri.%*.*lf",
               n_digits_to_show + 6, n_digits_to_show, arg_per * 180. / PI);
   if( format & SHOWELEM_OMIT_PQ_MASK)
      obuff[11 + precision] = '\0';
   else
      add_pq_data( obuff, p_vect[0], q_vect[0], precision);
   obuff += strlen( obuff) + 1;
   n_lines++;

   if( is_cometary || elem->ecc >= 1.)
      strcpy( obuff, nineteen_blank_spaces);
   else
      {
      *obuff = 'a';
      show_formatted_dist( obuff + 1, elem->major_axis, precision);
      }
   for( i = strlen( obuff); i < n_digits_to_show + 9; i++)
      obuff[i] = ' ';
   obuff[i] = '\0';
   obuff += strlen( obuff);

   sprintf( obuff, "Node %*.*lf", n_digits_to_show + 6, n_digits_to_show,
               asc_node * 180. / PI);
   if( format & SHOWELEM_OMIT_PQ_MASK)
      obuff[21] = '\0';
   else
      add_pq_data( obuff, p_vect[1], q_vect[1], precision);
   obuff += strlen( obuff) + 1;
   n_lines++;

   if( is_cometary)
      sprintf( obuff, "e   1.0            ");
   else
      {
      sprintf( obuff, "e%*.*lf", n_digits_to_show + 8,
                       n_digits_to_show + 3, elem->ecc);
      lop_digits( obuff + 8, precision);
      }
   obuff += strlen( obuff);

   sprintf( obuff, "Incl.%*.*lf", n_digits_to_show + 6, n_digits_to_show,
                 elem->incl * 180. / PI);
   if( format & SHOWELEM_OMIT_PQ_MASK)
      obuff[21] = '\0';
   else
      add_pq_data( obuff, p_vect[2], q_vect[2], precision);
   obuff += strlen( obuff) + 1;
   n_lines++;

   if( !is_cometary && elem->ecc < 1.)
      {
      const double t0 = elem->major_axis *
                      sqrt( elem->major_axis / planet_mass[elem->central_obj]);
      const double apoapsis_dist =
             perihelion_dist * (1. + elem->ecc) / (1. - elem->ecc);
      char tbuff[40];

      if( !elem->central_obj || t0 > 1.)         /* heliocentric */
         {
         if( t0 > 1e+8 - 1.)        /* too big to fit in buffer */
            obuff += sprintf( obuff, "P!!!!!!!");
         else if( t0 > 9999.)
            obuff += sprintf( obuff, "P%7ld", (long)t0);
         else
            obuff += sprintf( obuff, "P%7.2lf", t0);
         if( t0 * 365.25 < 999.9)
            obuff += sprintf( obuff, "/%6.2lfd ", t0 * 365.25);
         else
            obuff += sprintf( obuff, "         ");
         }
      else
         if( t0 > 1. / 365.25)
            obuff += sprintf( obuff, "P%7.2lfd        ", t0 * 365.25);
         else
            obuff += sprintf( obuff, "P%7.2lfm        ", t0 * 365.25 * 1440.);
      if( elem->abs_mag)
         {
         const char *output_format;

         if( elem->is_asteroid)
            output_format = "  H%7.1lf     G   %4.2lf";
         else
            output_format = "  M(T)%5.1lf    K %5.1lf";
         sprintf( obuff, output_format, elem->abs_mag + .05,
                                         elem->slope_param);
         if( !elem->is_asteroid)
            if( format & SHOWELEM_COMET_MAGS_NUCLEAR)
               obuff[4] = 'N';
         obuff += strlen( obuff);
         }

      strcat( obuff, "   q ");
      show_formatted_dist( tbuff, perihelion_dist, precision);
      for( i = 0; tbuff[i] == ' '; i++)   /* skip leading spaces */
         ;
      strcat( obuff, tbuff + i);

      strcat( obuff, "  Q ");
      show_formatted_dist( tbuff, apoapsis_dist, precision);
      for( i = 0; tbuff[i] == ' '; i++)   /* skip leading spaces */
         ;
      strcat( obuff, tbuff + i);
      n_lines++;
      }
   return( n_lines);
}