Esempio n. 1
0
void show_event( FILE *ofile, EVENT *e)
{
   char *event_str[4] = {"Occ", "Tra", "Ecl", "Sha"}, buff[80];
   const double ut_jd = e->t - td_minus_ut( e->t) / 86400.;

   if( e->event_type & EVENT_UNSEEN)
      return;
   full_ctime( buff, ut_jd, FULL_CTIME_FORMAT_HH_MM);
   fprintf( ofile, "sat %d: %s %s: %s\n", e->sat, event_str[e->event_type & 3],
              (e->event_type & EVENT_START) ? "start" : "end  ", buff);
}
Esempio n. 2
0
int main( int argc, char **argv)
{
   FILE *ifile = fopen( argc == 1 ? "get_test.txt" : argv[1], "rb");

   if( ifile)
      {
      char buff[80];
      double jd = 0;
      int i;
      unsigned time_format = 0;

      setvbuf( stdout, NULL, _IONBF, 0);
      while( fgets( buff, sizeof( buff), ifile))
         {
         for( i = 0; buff[i] >= ' '; i++)
            ;
         buff[i] = '\0';
         if( !memcmp( buff, "format", 6))
            {
            sscanf( buff + 6, "%x", &time_format);
            printf( "%s\n", buff);
            }
         else if( *buff != ';')
            {
            char obuff[80];
            int is_ut;

            jd = get_time_from_string( jd, buff, (int)time_format, &is_ut);
            full_ctime( obuff, jd, FULL_CTIME_MILLISECS | CALENDAR_JULIAN_GREGORIAN);
            printf( "%s %d %s\n", obuff, is_ut, buff);
            }
         else
            printf( "%s\n", buff);
         }
      fclose( ifile);
      }
   return( ifile ? 0 : -1);
}
Esempio n. 3
0
int main( const int argc, const char **argv)
{
   const double j2000 = 2451545.;    /* 1.5 Jan 2000 = JD 2451545 */
   int i, julian = 0, verbose = 0, chinese_calendar = 0;
   double t, t_centuries, t_cen2, t_cen3, t_cen4, t0, ut_time;
   double m, mp, f, e, max_date = 4000. * 365.25 + j2000;
   double lunar, dist, fund[N_FUND], rate = 29.5306, t_final;
   char buff[80];
   long long_to_write;
   double k;
   FILE *log_file = NULL, *vsop_file, *data_file = NULL;
   char *vsop_tbuff, FAR *vsop_data;
   time_t curr_time = time( NULL);

   vsop_file = fopen( "vsop.bin", "rb");
   if( !vsop_file)
      {
      printf( "Couldn't open vsop.bin");
      return( -1);
      }
   vsop_tbuff = (char *)malloc( VSOP_CHUNK);
   vsop_data = (char *)malloc( VSOP_CHUNK * 22U);
   for( i = 0; i < 22; i++)
      {
      if( !fread( vsop_tbuff, VSOP_CHUNK, 1, vsop_file))
         {
         printf( "Couldn't read VSOP data\n");
         return( -2);
         }
      FMEMCPY( vsop_data + (unsigned)i * VSOP_CHUNK, vsop_tbuff, VSOP_CHUNK);
      }
   fclose( vsop_file);
   free( vsop_tbuff);

   for( i = 0; i < argc; i++)
      if( argv[i][0] == '-')
         switch( argv[i][1])
            {
            case 'j': case 'J':
               julian = 1;
               break;
            case 'c': case 'C':
               chinese_calendar = 1;
               break;
            case 'v': case 'V':
               verbose = 1;
               break;
            case 'l': case 'L':
               log_file = fopen( argv[i] + 2, "wb");
               break;
            case 'd': case 'D':
               data_file = fopen( argv[i] + 2, "wb");
               break;
            case 'm': case 'M':
               max_date = (atof( argv[i] + 2) - 2000.) * 365.25 + j2000;
               break;
            default:
               break;
            }
   t0 = t = j2000 + 365.25 * (atof( argv[1]) - 2000.);
   k = floor( (atof( argv[1]) - 2000.) * 12.3685);
   if( data_file)
      {
      long_to_write = (long)k;
      fwrite( &long_to_write, 1, sizeof( long), data_file);
      }
   t_final = max_date - 1.;
   while( t_final < max_date)
      for( i = 0; i < 4; i++)
         {
         double t2, dlon_1, dlon_2, phase_angle, solar_lon, time_lag;
         static const char *phase_name[4] = {
                  "New moon ",
                  "1st qtr. ",
                  "Full moon",
                  "last qtr." };

         t_centuries = k / 1236.85;       /* first approx */
         t = 2451550.09765 + 29.530588853 * k
               + (1.337e-4 - 1.5e-7 * t_centuries) * t_centuries * t_centuries;
         t_centuries = (t - j2000) / 36525.;
         t_cen2 = t_centuries * t_centuries;
         t_cen3 = t_cen2 * t_centuries;
         t_cen4 = t_cen3 * t_centuries;
         m = 2.5534 + 29.10535669 * k
                    -  2.18e-5 * t_cen2
                    -  1.1e-7 * t_cen3;
         mp = 201.5643 + 385.81693528 * k
                       +    .0107438 * t_cen2
                       +   1.239e-5 * t_cen3
                       -   5.8e-8 * t_cen4;
         f = 160.7108 + 390.67050274 * k
                      -   1.6541e-3 * t_cen2
                      -   2.27e-6 * t_cen3
                      +   1.1e-8 * t_cen4;
         m *= PI / 180.;
         f *= PI / 180.;
         mp *= PI / 180.;
         e = 1. - .002516 * t_centuries - 7.4e-6 * t_cen2;
         switch( i)
            {
            case NEW_MOON:
               t +=   -.40720 * sin( mp)
                      +.17241 * sin( m) * e
                      +.01608 * sin( mp + mp)
                      +.01039 * sin( f + f)
                      +.00739 * sin( mp - m) * e
                      -.00514 * sin(  mp + m) * e
                      +.00208 * sin( m + m) * e * e
                      -.00111 * sin( mp - f - f);
               break;
            case FIRST_QUARTER:
            case LAST_QUARTER:
               t +=   -.62801 * sin( mp)
                      +.17172 * sin( m) *  e
                      -.01183 * sin( mp + m) * e
                      +.00862 * sin( mp + mp)
                      +.00804 * sin( f + f)
                      +.00454 * sin( mp - m) * e
                      +.00204 * sin( m + m) * e * e
                      -.00180 * sin( mp - f - f);
               t += ((i == FIRST_QUARTER) ? .00306 : -.00306);
               break;
            case FULL_MOON:
               t +=   -.40614 * sin( mp)
                      +.17302 * sin( m) * e
                      +.01614 * sin( mp + mp)
                      +.01043 * sin( f + f)
                      +.00734 * sin( mp - m) * e
                      -.00515 * sin(  mp + m) * e
                      +.00209 * sin( m + m) * e * e
                      -.00111 * sin( mp - f - f);
               break;
            default:
               break;
            }
         phase_angle = (double)i * 90.;
         t_centuries = (t - j2000) / 36525.;
         time_lag = approx_solar_dist( t_centuries) / SPEED_OF_LIGHT;
         time_lag /= 86400. * 36525.;
         lunar_fundamentals( vsop_data, t_centuries, fund);
         lunar_lon_and_dist( vsop_data, fund, &lunar, &dist, 0L);
         solar_lon = calc_vsop_loc( vsop_data, 3, 0, t_centuries - time_lag, 0.);
         solar_lon = solar_lon * 180. / PI - 180.;
         dlon_1 = lunar - solar_lon - phase_angle;
         while( dlon_1 < -180.) dlon_1 += 360.;
         while( dlon_1 >  180.) dlon_1 -= 360.;
         if( verbose)
            {
            full_ctime( buff, t, julian);
            printf( "   first  time is %s;  lon diff %lf\n", buff, dlon_1);
            }

         t2 = t - rate * dlon_1 / 360.;
         t_centuries = (t2 - j2000) / 36525.;
         lunar_fundamentals( vsop_data, t_centuries, fund);
         lunar_lon_and_dist( vsop_data, fund, &lunar, &dist, 0L);
         solar_lon = calc_vsop_loc( vsop_data, 3, 0, t_centuries - time_lag, 0.);
         solar_lon = solar_lon * 180. / PI - 180.;
         dlon_2 = lunar - solar_lon - phase_angle;
         while( dlon_2 < -180.) dlon_2 += 360.;
         while( dlon_2 >  180.) dlon_2 -= 360.;
         if( verbose)
            {
            full_ctime( buff, t2, julian);
            printf( "   second time is %s;  lon diff %lf\n", buff, dlon_2);
            }
         t_final = (t * dlon_2 - t2 * dlon_1) / (dlon_2 - dlon_1);
         ut_time = t_final - td_minus_ut( t_final) / 86400.;
         full_ctime( buff, ut_time, julian);
         if( log_file)
            {
            if( chinese_calendar)
               fprintf( log_file, "%7ld    %s\n",
                                (long)floor( ut_time - 1. / 6.), buff);
            else
               fprintf( log_file, "%s: %s\n", phase_name[i], buff);
            }
         buff[17] = '\0';        /* trim the seconds */
         if( !chinese_calendar)
            {
            printf( "%s  ", buff);
            if( i == 3)
               printf( "\n");
            }
         if( data_file)
            {
            double diff = t_final - ( 2451550.09765 + 29.530588853 * k);

            diff *= 86400.;
            if( verbose)
               printf( "Time diff %lf\n", diff);
            long_to_write = (long)diff;
            fwrite( &long_to_write, 1, sizeof( long), data_file);
            }
         if( chinese_calendar)
            {
            k++;
            i = 4;
            }
         else        /* just moving to next _phase_ */
            k += .25;
         if( curr_time != time( NULL))
            {
            curr_time = time( NULL);
            printf( "JD %.3lf (%.3lf)\r", t_final,
                     (t_final - j2000) / 365.25 + 2000.);
            }
         }

   if( chinese_calendar)
      while( t0 < max_date)
         {
         double t_centuries, time_lag, delta_t = 1.;
         double solar_lon;
         const double thirty_deg = PI / 6.;
         long solar_month = 0L, year;

         while( fabs( delta_t) > .00001)  /* resolution a little better than 1s */
            {
            t_centuries = (t0 - j2000) / 36525.;
            time_lag = approx_solar_dist( t_centuries) / SPEED_OF_LIGHT;
            time_lag /= 86400. * 36525.;
            solar_lon = calc_vsop_loc( vsop_data, 3, 0, t_centuries - time_lag, 0.);
            solar_month = (long)floor( solar_lon / thirty_deg + .5);
            solar_lon -= (double)solar_month * thirty_deg;
            delta_t = solar_lon * 365.25 / (2. * PI);
            t0 -= delta_t;
            if( verbose)
               printf( "delta_t: %.5lf   JD %.5lf\n", delta_t, t0);
            }
         solar_month = (solar_month + 7) % 12;  /* flip around to winter sol */
         year = (long)
                  floor( (t0 - (double)solar_month * 30.5 - 100.) / 365.25);
         year -= 2074L;
         ut_time = t0 - td_minus_ut( t0) / 86400.;
         full_ctime( buff, ut_time, julian);
         if( log_file)
            fprintf( log_file, "%7ld z  %s  %2ld %5ld\n",
                          (long)floor( ut_time - 1. / 6.),
                          buff, solar_month + 1, year);
         if( curr_time != time( NULL))
            {
            curr_time = time( NULL);
            printf( "%7ld z  %s   %2ld %5ld: %.3lf\n",
                          (long)floor( ut_time - 1. / 6.),
                          buff, solar_month + 1, year,
                          (ut_time - j2000) / 365.25 + 2000.);
            }
         t0 += 365.25 / 12.;
         }
   fclose( data_file);
   fclose( log_file);
   return( 0);
}
Esempio n. 4
0
int main( const int argc, const char **argv)
{
   char tbuff[300], mpc_code[20];
   char **summary_lines = NULL;
   const char *separate_residual_file_name = NULL;
   const char *mpec_path = NULL;
   int n_ids, i, starting_object = 0;
   int n_processes = 1;
   OBJECT_INFO *ids;
   int total_objects = 0;
   FILE *ifile;
   extern int process_count;
   int n_lines_written = 0;
   FILE *summary_ofile = NULL;
   extern int forced_central_body;
   extern int use_config_directory;          /* miscell.c */
   int element_precision = 5;
   bool all_heliocentric = true;
   bool use_colors = true;
   bool show_processing_steps = true;
   int ephemeris_output_options = OPTION_SHOW_SIGMAS | OPTION_ROUND_TO_NEAREST_STEP;
   time_t update_time, t0;
   double ephem_end_jd = 0.;
   extern bool is_default_ephem;
   bool drop_single_obs = true;
   const char *ephem_option_string = NULL;
#ifdef FORKING
   int child_status;
#endif

   if( !strcmp( argv[0], "fo"))
      use_config_directory = true;
   else
      use_config_directory = false;
   *mpc_code = '\0';
   for( i = 1; i < argc; i++)       /* check to see if we're debugging: */
      if( argv[i][0] == '-')
         {
         const char *arg = get_arg( argc, argv, i);

         switch( argv[i][1])
            {
            case 'a':
               {
               extern int separate_periodic_comet_apparitions;

               separate_periodic_comet_apparitions ^= 1;
               }
               break;
            case 'b':
               separate_residual_file_name = arg;
               break;
            case 'c':
               {
               extern int combine_all_observations;

               combine_all_observations = 1;
               }
               break;
            case 'C':
               strlcpy( mpc_code, arg, sizeof( mpc_code));
               break;
            case 'd':
               debug_level = atoi( arg);
               if( !debug_level)
                  debug_level = 1;
               debug_printf( "fo: debug_level = %d; %s %s\n",
                           debug_level, __DATE__, __TIME__);
               break;
            case 'e':
               {
               extern const char *ephemeris_filename;

               ephemeris_filename = arg;
               is_default_ephem = false;
               }
               break;
            case 'E':
               ephem_option_string = arg;
               break;
            case 'f':                     /* obj desig specified;  fall through */
               break;
            case 'h':                     /* show planet-centric orbits */
               all_heliocentric = false;
               break;
#ifdef FORKING
            case 'k':
               unlink_partial_files = false;
               break;
#endif
            case 'i':
               {
               extern int ignore_prev_solns;

               ignore_prev_solns = 1;
               }
               break;
            case 'm':
               mpec_path = arg;
               break;
            case 'M':
               {
               extern const char *mpcorb_dot_sof_filename;

               mpcorb_dot_sof_filename = arg;
               }
               break;
            case 'n':
               starting_object = atoi( arg);
               break;
            case 'O':          /* write output files to specified dir */
               {
               extern const char *output_directory;

               output_directory = arg;
               }
               break;
            case 'o':            /* obj designation / ephemeris from orbital */
               break;            /* elems:  fall through, handle below */
            case 'p':
               {
               FILE *ifile = fopen_ext( "dummy.txt", "tfcw");

               fclose( ifile);
               n_processes = atoi( arg);
               }
               break;
            case 'q':            /* "quiet" */
               show_processing_steps = false;
               break;
#ifdef FORKING
            case 'r':
               {                    /* set 'soft' & 'hard' limits for CPU */
               struct rlimit r;     /* run time,  in seconds,  to avoid   */
               int soft_limit, hard_limit;      /* runaway processes */

               if( sscanf( arg, "%d,%d", &soft_limit, &hard_limit) == 2)
                  {
                  r.rlim_cur = (rlim_t)soft_limit;
                  r.rlim_max = (rlim_t)hard_limit;
                  setrlimit( RLIMIT_CPU, &r);
                  }
               }
               break;
#endif
            case 's':
               sanity_test_observations( argv[1]);
               printf( "Sanity check complete\n");
               return( 0);
            case 'S':
               {
               char curr_time[50];

               full_ctime( curr_time, current_jd( ), FULL_CTIME_YMD);
               summary_ofile = fopen( arg, "wb");
               assert( summary_ofile);
               ifile = fopen_ext( "summ.htm", "fcrb");
               assert( ifile);
               while( fgets( tbuff, sizeof( tbuff), ifile))
                  {
                  text_search_and_replace( tbuff, "%TIME%", curr_time);
                  fputs( tbuff, summary_ofile);
                  }
               fclose( ifile);
               }
               break;
            case 't':
               if( argv[i][2] == 'e' || argv[i][2] == 'E')
                  {
                  double jd = get_time_from_string( curr_jd( ), argv[i] + 3,
                           CALENDAR_JULIAN_GREGORIAN | FULL_CTIME_YMD
                           | FULL_CTIME_TWO_DIGIT_YEAR, NULL);

                  if( argv[i][2] == 'e')
                     ephem_end_jd = jd;
                  else
                     {
                     extern double override_epoch_shown;

                     override_epoch_shown = jd;
                     }
                  }
               else
                  total_objects = atoi( arg);
               break;
            case 'v':
               use_colors = false;
               break;
            case 'z':
               use_config_directory = true;
               break;
            default:
               printf( "Unknown command-line option '%s'\n", argv[i]);
               return( -1);
            }
         }
   for( i = 1; i < argc; i++)
      {
      const char *tptr = strchr( argv[i], '=');

      if( tptr && argv[i][0] != '-')
         {
         const size_t len = tptr - argv[i];

         memcpy( tbuff, argv[i], len);
         tbuff[len] = '\0';
         set_environment_ptr( tbuff, argv[i] + len + 1);
         }
      }

               /* get_defaults( ) collects a lot of data that's for the  */
               /* interactive find_orb program.  But it also sets some   */
               /* important internal values for blunder detection,  etc. */
               /* So we still call it:                                   */
   get_defaults( &ephemeris_output_options,
                         NULL, &element_precision, NULL, NULL);
   if( all_heliocentric)
      forced_central_body = 0;
   if( ephem_option_string)
      ephemeris_output_options = (int)parse_bit_string( ephem_option_string);

   load_up_sigma_records( "sigma.txt");
   if( debug_level)
      debug_printf( "%d sigma recs read\n", i);

   if( argc < 2)
      {
      printf( "'fo' needs the name of an input file of MPC-formatted\n");
      printf( "astrometry as a command-line argument.\n");
      return( -2);
      }

   if( reset_astrometry_filename( argc, argv))
      drop_single_obs = false;

   ids = find_objects_in_file( argv[1], &n_ids, NULL);
   if( n_ids <= 0)
      {        /* no objects found,  or file not found */
      const char *err_msg;

      if( n_ids == -1)
         err_msg = "Couldn't locate the file";
      else
         err_msg = "No objects found in file";
      printf( "%s '%s'\n", err_msg, argv[1]);
      return( -1);
      }

   if( drop_single_obs)
      n_ids = remove_single_observation_objects( ids, n_ids);
   if( show_processing_steps)
      printf( "Processing %d objects\n", n_ids);
   if( !total_objects)
      total_objects = n_ids;

   t0 = update_time = time( NULL);
#ifdef FORKING
   while( process_count < n_processes - 1)
      {
      const pid_t childpid = fork( );

      if( childpid == -1)      /* fork( ) returns -1 on failure */
         {
         perror("fork"); /* display error message */
         exit(0);
         }
      else if( childpid == 0)     /* we're a child process */
         {
//       printf( "Hi!  I'm child %d.  My PID is %d; parent's is %d\n",
//                process_count, getpid( ), getppid( ));
         }
      else
         break;       /* break out of loop,  signalling we're a parent */
      process_count++;
      }
   if( n_processes > 1)
      process_count++;
   if( show_processing_steps)
      printf( "Process count %d\n", process_count);
#endif

   if( summary_ofile)
      summary_lines = (char **)calloc( n_ids - starting_object + 1,
                                                    sizeof( char *));
   ifile = fopen( argv[1], "rb");
   if( total_objects > n_ids - starting_object)
      total_objects = n_ids - starting_object;
   for( i = starting_object; i < starting_object + total_objects; i++)
      if( n_processes == 1 || i % n_processes == process_count - 1)
         {
         const char *orbit_constraints = "";
         OBSERVE FAR *obs;
         const int n_obs = ids[i].n_obs;

         if( n_processes == 1 && show_processing_steps)
            printf( "%d: %s", i + 1, ids[i].obj_name);
         if( n_obs < 2 && drop_single_obs)
            printf( "; skipping\n");
         else
            {
            extern int append_elements_to_element_file;
            extern int n_obs_actually_loaded;
            extern char orbit_summary_text[];
            long file_offset = ids[i].file_offset - 40L;
            int element_options = ELEM_OUT_ALTERNATIVE_FORMAT;
            double epoch_shown, curr_epoch, orbit[12];

            if( all_heliocentric)
               element_options |= ELEM_OUT_HELIOCENTRIC_ONLY;
                /* Start a bit ahead of the actual data,  just in case */
                /* there's a #Sigma: or similar command in there: */
            if( file_offset < 0L)
               file_offset = 0L;
            fseek( ifile, file_offset, SEEK_SET);
            obs = load_object( ifile, ids + i, &curr_epoch, &epoch_shown, orbit);

            if( (n_obs_actually_loaded > 1 || !drop_single_obs) && curr_epoch > 0.)
               {
               int n_obs_included = 0;
               unsigned j = 0;

               write_out_elements_to_file( orbit, curr_epoch, epoch_shown,
                     obs, n_obs_actually_loaded, orbit_constraints, element_precision,
                     0, element_options);
               strcpy( tbuff, orbit_summary_text);
               if( use_colors)
                  colorize_text( tbuff);
               if( show_processing_steps)
                  {
                  if( n_processes > 1)
                     {
                     if( process_count == 1 && time( NULL) != update_time)
                        {
                        int elapsed, n_done = i - starting_object + 1;

                        update_time = time( NULL);
                        elapsed = (int)update_time - (int)t0;
                        printf( "%d seconds elapsed, %d remain\n", elapsed,
                               elapsed * (total_objects - n_done) / n_done);
                        }
                     printf( "(%d) %d: %s", process_count, i + 1, ids[i].obj_name);
                     }
                  printf( "; %s ", tbuff);
                  }
               if( separate_residual_file_name)
                  {
                  extern bool residual_file_in_config_dir;

                  residual_file_in_config_dir = false;
                  write_residuals_to_file( separate_residual_file_name, argv[1],
                               n_obs_actually_loaded, obs, RESIDUAL_FORMAT_PRECISE
                               | RESIDUAL_FORMAT_COMPUTER_FRIENDLY
                               | RESIDUAL_FORMAT_FOUR_DIGIT_YEARS
                               | RESIDUAL_FORMAT_EXTRA);
                  residual_file_in_config_dir = true;
                  }
               if( !mpec_path)
                  append_elements_to_element_file = 1;
               if( mpec_path || !is_default_ephem)
                  {
                  int n_orbits_in_ephem = 1;
                  int n_ephemeris_steps = 50;
                  char ephemeris_step_size[20];
                  extern const char *ephemeris_filename;
                  extern const char *residual_filename;
                  extern int available_sigmas;
                  extern double ephemeris_mag_limit;
                  double *orbits_to_use = orbit;
                  const double jd_start = get_time_from_string( curr_jd( ),
                           get_environment_ptr( "EPHEM_START"),
                           CALENDAR_JULIAN_GREGORIAN | FULL_CTIME_YMD
                           | FULL_CTIME_TWO_DIGIT_YEAR, NULL);

                  sscanf( get_environment_ptr( "EPHEM_STEPS"), "%d %9s",
                         &n_ephemeris_steps, ephemeris_step_size);
                  if( ephem_end_jd)
                     {
                     n_ephemeris_steps = 1;
                     snprintf( ephemeris_step_size,
                           sizeof( ephemeris_step_size),
                           "%f", ephem_end_jd - jd_start);
                     }
                  if( !*mpc_code)
                     sscanf( get_environment_ptr( "CONSOLE_OPTS"), "%9s",
                                 mpc_code);
                  create_obs_file( obs, n_obs_actually_loaded, 0);
                  ephemeris_mag_limit = 999.;
                  if( available_sigmas == COVARIANCE_AVAILABLE)
                     {
                     n_orbits_in_ephem = 2;
                     compute_variant_orbit( orbit + 6, orbit, 1.);
                     }
                  if( available_sigmas == SR_SIGMAS_AVAILABLE)
                     {
                     extern double *sr_orbits;
                     extern unsigned n_sr_orbits;

                     orbits_to_use = sr_orbits;
                     n_orbits_in_ephem = n_sr_orbits;
                     }
                  if( !ephemeris_in_a_file_from_mpc_code( ephemeris_filename,
                              orbits_to_use, obs, n_obs_actually_loaded,
                              curr_epoch, jd_start, ephemeris_step_size,
                              n_ephemeris_steps, mpc_code,
                              ephemeris_output_options,
                              n_orbits_in_ephem))
                     {
                     write_residuals_to_file( residual_filename, argv[1],
                                    n_obs_actually_loaded, obs, RESIDUAL_FORMAT_SHORT);
                     if( mpec_path)
                        {
                        char fullpath[100];

                        sprintf( fullpath, "%s/%s.htm", mpec_path, ids[i].packed_desig);
                        text_search_and_replace( fullpath, " ", "");

                        make_pseudo_mpec( fullpath, ids[i].obj_name);
                        get_summary_info( tbuff, fullpath);
                        if( summary_ofile)
                           {
                           FILE *ephemeris_ifile = fopen_ext( ephemeris_filename, "tfcrb");
                           char new_line[420];

                           tbuff[14] = '\0';
                           snprintf( new_line, sizeof( new_line), "<a href=\"%s\">%s</a>%s",
                                    fullpath, tbuff, tbuff + 15);
                           memset( tbuff, 0, sizeof( tbuff));
                           while( j < 4 && fgets_trimmed( tbuff, sizeof( tbuff),
                                                         ephemeris_ifile))
                              j++;
                           if( j == 4)
                              {
                              tbuff[23] = tbuff[39] = tbuff[73] = '\0';
                              sprintf( new_line + strlen( new_line), "  %s  %s  %s",
                                       tbuff + 15, tbuff + 30, tbuff + 57);
                                             /* now add sigma from end of ephem: */
                              while( fgets_trimmed( tbuff, sizeof( tbuff), ephemeris_ifile))
                                 ;
                              tbuff[73] = '\0';
                              sprintf( new_line + strlen( new_line), "%s", tbuff + 68);
                              }
                           fclose( ephemeris_ifile);
                           summary_lines[n_lines_written]
                                      = (char *)malloc( strlen( new_line) + 1);
                           strcpy( summary_lines[n_lines_written], new_line);
                           n_lines_written++;
                           }
                        }
                     }
                  }

               for( j = 0; j < (unsigned)n_obs_actually_loaded; j++)
                  if( obs[j].is_included)
                     n_obs_included++;
               if( n_obs_included != n_obs_actually_loaded
                              && show_processing_steps)
                  {
                  if( use_colors)        /* reverse colors to draw attn */
                     printf( "\033[30;47m");
                  printf( " %d /", n_obs_included);
                  }
               }
            else
               printf( "; not enough observations\n");
            unload_observations( obs, n_obs_actually_loaded);
            }
         object_comment_text( tbuff, ids + i);
                  /* Abbreviate 'observations:' to 'obs:' */
         text_search_and_replace( tbuff, "ervations", "");
         if( show_processing_steps)
            printf( "  %s\n", tbuff);
         if( use_colors)
            printf( "\033[0m");
         }
   free( ids);
   if( summary_ofile)
      {
      int pass;

      for( pass = 0; pass < 4; pass++)
         {
         const char *headers[4] = {
               "<h3><a name=\"desig\">Sorted by designation</a></h3>",
               "<h3><a name=\"unc\">Sorted by current ephemeris uncertainty</a></h3>",
               "<h3><a name=\"moid\">Sorted by Earth MOID</a></h3>",
               "<h3><a name=\"mag\">Sorted by magnitude</a></h3>" };
         const char *ephem_header =
             "Object            Semimajor axis    Eccentricity        Incl         "
             "MOID           RA        dec      Elong mag  Sig1  Sig2";

         fprintf( summary_ofile, "\n%s\n", headers[pass]);
         fprintf( summary_ofile, "%s\n\n", ephem_header);
         if( pass)
            {
            static int columns[] = { 0, 123, 77, 118 };

            summ_sort_column = columns[pass];
            qsort( summary_lines, n_lines_written, sizeof( char *), summ_compare);
            }
         for( i = 0; summary_lines[i]; i++)
            {
            fprintf( summary_ofile, "%s%s", summary_lines[i],
                ( i % 5 == 4) ? "\n\n" : "\n");
            }
         }
      for( i = 0; summary_lines[i]; i++)
         free( summary_lines[i]);
      free( summary_lines);
      fprintf( summary_ofile, "</body> </html>\n");
      fclose( summary_ofile);
      }
   fclose( ifile);
#ifdef FORKING
   if( show_processing_steps)
      printf( "Process %d is done\n", process_count);
   wait( &child_status); /* wait for child to exit, and store its status */
   if( process_count == 1)
      {
      extern const char *elements_filename;
      extern const char *mpc_fmt_filename;

      combine_element_files( elements_filename, n_processes);
      combine_element_files( mpc_fmt_filename, n_processes);
      combine_element_files( sof_filename, n_processes);
      combine_element_files( sofv_filename, n_processes);
      for( i = 0; i < n_processes; i++)
         {                             /* clean up temp files: */
         process_count = i + 1;
         unlink_config_file( "monte.txt");
         unlink_config_file( "guide.txt");
         unlink_config_file( "covar.txt");
         unlink_config_file( "sr_elems.txt");
         unlink_config_file( "mpc_sr.txt");
//       unlink_config_file( sof_filename);
         }
      }
#ifdef TEST_PLANET_CACHING_HASH_FUNCTION
   if( process_count == 0)
      {
      extern int64_t planet_ns;
      extern long total_n_searches, total_n_probes, max_probes_required;

      printf( "  tp:%ld.%09ld\n",
                  (long)( planet_ns / (int64_t)1000000000),
                  (long)( planet_ns % (int64_t)1000000000));
      printf( "%ld searches; %ld probes; %ld max probes\n",
                  total_n_searches, total_n_probes, max_probes_required);
      }
#endif
#endif
   clean_up_find_orb_memory( );
   return( 0);
}
Esempio n. 5
0
int main( const int argc, const char **argv)
{
   FILE *ifile = fopen( argv[1], "rb");
   char buff[200], results[6][100];
   char exp_text[100];
   double roll_ang = 0.;

   assert( ifile);
   *exp_text = '\0';
   printf( "# (J95) Great Shefford logs,  processed with j95_xvt.c (q.v.)\n");
#ifdef __TIMESTAMP__
   printf( "# Source file date %s\n", __TIMESTAMP__);
#else
   printf( "# Version %s %s\n", __DATE__, __TIME__);
#endif
   printf( "# Input file '%s'\n", argv[1]);
   while( fgets( buff, sizeof( buff), ifile))
      {
      size_t i, j, k;
      double jd;
      char *time_str = results[1];

      for( i = j = 0; buff[i]; i++)    /* remove quote marks */
         if( buff[i] != '"')
            buff[j++] = buff[i];
      buff[j] = '\0';
      for( i = j = 0; i < 6; i++)
         {
         k = j;
         while( buff[k] != ',' && buff[k] >= ' ')
            k++;
         assert( k > j);
         assert( buff[k] == ',' || i == 5);
         memcpy( results[i], buff + j, k - j);
         results[i][k - j] = '\0';
         j = k + 1;        /* skip the comma */
         }
      jd = get_time_from_string( 0., time_str, FULL_CTIME_DMY, NULL);
      if( jd > 2e+6)
         {
         const double exposure_time = atof( results[4]) / seconds_per_day;
         const double ra = get_angle( results[2]) * 15.;
         const double dec = get_angle( results[3]);
         const double new_roll_ang = atof( results[5]);

         if( strcmp( exp_text, results[4]))
            {
            strcpy( exp_text, results[4]);
            printf( "# Exposure: %s s\n", exp_text);
            }
         if( fabs( roll_ang - new_roll_ang) > .5)
            {
            roll_ang = new_roll_ang;
            printf( "# Tilt: %.1f\n", roll_ang);
            }
         jd += exposure_time / 2.;
         full_ctime( time_str, jd, FULL_CTIME_YMD | FULL_CTIME_MILLISECS
                        | FULL_CTIME_MONTHS_AS_DIGITS | FULL_CTIME_LEADING_ZEROES);
         time_str[4] = time_str[7] = '-';
         time_str[10] = 'T';
         printf( "%.3f,%.3f,%s,J95,%s\n",
                              ra, dec, time_str, results[0]);
         }
      }
   fclose( ifile);
   return( 0);
}
Esempio n. 6
0
static void search_conjunctions( void *jpleph,
              const double t0, const double step_size0,
              const double *loc1, const double *loc2, const double *loc3)
{
   int i, j;

   for( i = 0; i < N_OBJECTS; i++)
      for( j = 0; j < i; j++)
         if( is_used[i] && is_used[j] && (j != 3 || i != 10))
            {
            double dsquared[3], occult_margin, inner_margin;
            int pass;
            double t = t0, step_size = step_size0, jd;
            char obuff[80];

            dsquared[0] = rough_dist2( loc1 + i * 3, loc1 + j * 3);
            dsquared[1] = rough_dist2( loc2 + i * 3, loc2 + j * 3);
            dsquared[2] = rough_dist2( loc3 + i * 3, loc3 + j * 3);
            if( dsquared[1] < dsquared[0] && dsquared[1] < dsquared[2])
               {
               char buff[80];
               double loc[3 * N_OBJECTS], idist, jdist;
               static double planet_radii[N_OBJECTS] = { 696265., 2439.,
                        6051., 6378., 3393., 71398., 60000.,
                        25400., 25295., 1137., 1737.53 };
               static double planet_inner[N_OBJECTS] = { 696265., 2439.,
                        6051., 6378. * (1. - .00335281),
                               3393. * (1. - .0051865),
                              71398. * (1. - .0648088),
                              60000. * (1. - .1076209),
                              25400. * (1. - .03),
                              25295. * (1. - .022), 1137., 1737.53 };
               char t_used[N_OBJECTS];

               memset( t_used, 0, N_OBJECTS);
               t_used[home_planet] = t_used[i] = t_used[j] = 1;
               for( pass = 5; pass; pass--)
                  {
                  double minval = (dsquared[0] - dsquared[2]) /
                        (2. * (dsquared[2] + dsquared[0] - 2. * dsquared[1]));

                  t += (minval - 1.) * step_size;
                  step_size *= .1;
                  if( pass > 1)        /* still gotta refine estimate */
                     {
                     int k;

                     for( k = 0; k < 3; k++)
                        {
                        find_posns( jpleph, loc,
                                  t + (double)(k - 2) * step_size, 2, t_used);
                        dsquared[k] = rough_dist2( loc + i * 3, loc + j * 3);
                        }
                     }
//                if( i == 3 && j == 0)
//                   printf( "%d: %lf (%lf)\n", pass, t,
//                                sqrt( dsquared[1]) * 180. / PI);
                  }
               idist = loc[i * 3 + 2];
               jdist = loc[j * 3 + 2];
               jd = 2451545.0 + (t - 2000.) * 365.25;
               if( jdist > idist)
                  {
                  occult_margin = planet_radii[home_planet] + idist *
                             (planet_radii[j] - planet_radii[home_planet]) / jdist;
                  occult_margin = (occult_margin + planet_radii[i]) / idist;
                  inner_margin = planet_inner[home_planet] + idist *
                             (planet_inner[j] - planet_inner[home_planet]) / jdist;
                  inner_margin = (inner_margin + planet_inner[i]) / idist;
                  }
               else
                  {
                  occult_margin = planet_radii[home_planet] + jdist *
                             (planet_radii[i] - planet_radii[home_planet]) / idist;
                  occult_margin = (occult_margin + planet_radii[j]) / jdist;
                  inner_margin = planet_inner[home_planet] + jdist *
                             (planet_inner[i] - planet_inner[home_planet]) / idist;
                  inner_margin = (inner_margin + planet_inner[j]) / jdist;
                  }
               occult_margin /= AU_IN_KM;
               inner_margin /= AU_IN_KM;
               full_ctime( buff, jd, 0);
               dsquared[1] = sqrt( dsquared[1]);
               sprintf( obuff, "%2d %2d%7.3lf  %s", i, j,
                              (180. / PI) * dsquared[1], buff);
               if( occult_margin > dsquared[1])
                  {
                  if( j)      /* planet-planet event */
                     obuff[5] = 'M';
                  else if( idist < jdist)
                     obuff[5] = 'T';
                  if( inner_margin < dsquared[1])
                     obuff[6] = '?';         /* indicate 'possible' */
                  }
               if( !occultations_only || obuff[5] == 'M' || obuff[5] == 'T')
                  {
                  printf( "%s\n", obuff);
                  if( log_file)
                     {
                     obuff[13] = '^';
                     fprintf( log_file, "%s//tdj%12.4lf;gp%02d;gp%02d^\n", obuff,
                                          jd, i, j);
                     }
                  }
               }
            }
}
Esempio n. 7
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);
}