# include "relastro.h"

void initialize (int argc, char **argv) {

  int NPHOTCODES;
  char *codename, *ptr;

  ConfigInit (&argc, argv);
  args (argc, argv);

  /* XXX we need to build a list of accepted photcodes. these will be used by bcatalog to accept or
     reject loaded data */

  Nphotcodes = 0;
  photcodes = NULL;
  if (PHOTCODE_LIST != NULL) {
    NPHOTCODES = 10;
    ALLOCATE (photcodes, PhotCode *, NPHOTCODES);

    /* parse the comma-separated list of photcodes */
    strtok_r (PHOTCODE_LIST, ",", &ptr);
    while ((codename = strtok_r (NULL, ",", &ptr)) != NULL) {
      fprintf (stderr, "PHOTCODE_LIST: %s\n", PHOTCODE_LIST);
      fprintf (stderr, "codename: %s\n", codename);
      if ((photcodes[Nphotcodes] = GetPhotcodebyName (codename)) == NULL) {
	fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
	exit (1);
      }
      Nphotcodes ++;
      CHECK_REALLOCATE (photcodes, PhotCode *, NPHOTCODES, Nphotcodes, 10);
    }
  }
  PhotNsec = GetPhotcodeNsecfilt ();

  initstats (STATMODE);

  IMAGE_BAD = ID_IMAGE_POOR | ID_IMAGE_FEW | ID_IMAGE_SKIP;
  STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
  MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR | ID_MEAS_SKIP | ID_MEAS_AREA;

  /* XXX drop irrelevant entries */
  if (SHOW_PARAMS) {
    fprintf (stderr, "current parameter settings:\n");
    if (TimeSelect) {
      fprintf (stderr, "TimeSelect: TRUE (%s - %s)\n", ohana_sec_to_date (TSTART), ohana_sec_to_date (TSTOP));
    } else {
      fprintf (stderr, "TimeSelect: FALSE\n");
    }
    fprintf (stderr, "VERBOSE: %d, PLOTSTUFF: %d\n", VERBOSE, PLOTSTUFF);

    fprintf (stderr, "MAG_LIM                %lf\n", MAG_LIM);
    fprintf (stderr, "STAR_SCATTER           %lf\n", STAR_SCATTER);
    fprintf (stderr, "IMAGE_SCATTER          %lf\n", IMAGE_SCATTER);
    fprintf (stderr, "IMAGE_OFFSET           %lf\n", IMAGE_OFFSET);
    fprintf (stderr, "IMAGE_CATALOG          %s\n",  ImageCat);
    fprintf (stderr, "GSCFILE                %s\n",  GSCFILE);
    fprintf (stderr, "CATDIR                 %s\n",  CATDIR);
    exit (0);
  }
}

