# include "markstar.h"

main (argc, argv)
int argc;
char **argv;
{

  FILE *f;
  int i, Nimages;
  Image *image, *find_images();
  Catalog catalog;
  CatStats catstats;
  struct timeval now, then;  
  
  gettimeofday (&then, (void *) NULL);
  ConfigInit (argc, argv);

  VERBOSE = FALSE;
  if ((i = get_argument (argc, argv, "-v"))) {
    VERBOSE = TRUE;
    remove_argument (i, &argc, argv);
  }
  if (argc < 2) {
    fprintf (stderr, "ERROR: Usage: fixcat (catalog)\n");
    exit (0);
  }

  /* if lockfile exists, program will complain and quit */
  check_lockfile (); 

  gcatalog (argv[1], &catalog);

  gcatstats (&catalog, &catstats);

  image = find_images (&catstats, &Nimages);

  match_images (&catalog, image, Nimages);
    
  find_funnymags (&catalog, image, Nimages);  

  if (VERBOSE) {
    gettimeofday (&now, (void *) NULL);
    fprintf (stderr, "%s: elapsed time = %.2f sec\n", argv[1], 
	     (now.tv_sec - then.tv_sec) + 1e-6*(now.tv_usec - then.tv_usec));
  }
  clear_lockfile (); 
  fprintf (stderr, "SUCCESS\n");
}

