# include "addstar.h"

void resort_catalog (Catalog *catalog) {

  int *next_meas;
  int 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 %7d measures, %6d average\n", dtime, Nmeas, Naves);

  return;
}
