# include "addstar.h"

void resort_catalog (Catalog *catalog) {

  off_t *next_meas;
  off_t Naves, Nmeas;
  double dtime;
  struct timeval start, stop;

  if (catalog[0].sorted == TRUE) return;

  gettimeofday (&start, NULL);

  /* internal counters */
  Nmeas = catalog[0].Nmeasure;
  Naves = catalog[0].Naverage;
  
  /* set up pointers for linked list of measure, missing */
  next_meas = build_measure_links (catalog[0].average, Naves, catalog[0].measure, Nmeas);

  catalog[0].sorted = TRUE;
  catalog[0].measure = sort_measure (catalog[0].average, Naves, catalog[0].measure, Nmeas, next_meas);

  gettimeofday (&stop, NULL);
  dtime = DTIME (stop, start);
  fprintf (stderr, "  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeas, (long long) Naves);

  return;
}
