# include "markstar.h"

gcatalog (char *catname, Catalog *catalog) {
  
  char filename[128];
  int i, status, mode;
  unsigned int NotTrail;
  unsigned short NotBad;

  sprintf (filename, "%s/%s\0", CATDIR, catname);

  mode = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
  status = load_catalog (filename, catalog, mode, VERBOSE);

  switch (status) {
  case 2:
  case 0:
    exit (0);
  case 1:
    break;
  } 
  if (catalog[0].Nsecfilt != photcodes.Nsecfilt) {
    fprintf (stderr, "ERROR: mismatch in secondary photometry values\n");
    exit (0);
  }

  if (RESET) {
    NotBad = (0xffff ^ 0xc003);
    for (i = 0; i < catalog[0].Naverage; i++) {
      if ((catalog[0].average[i].code & ID_MOVING) &&
	  (catalog[0].average[i].code & ID_BAD_OBJECT) &&
	  (catalog[0].average[i].code & 0x0003)) {
	/* this will set the correct bit for each to 0 */ 
	catalog[0].average[i].code &= NotBad;
      }
    }
    for (i = 0; i < catalog[0].Nmeasure; i++) {
      catalog[0].measure[i].average &= ~PART_OF_TRAIL;
    }
  }
}
