# include "relphot.h"

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

  int N;

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

  N = UserPatchSelect ? 1 : 2;
  if ((photcode = GetPhotcodebyName (argv[N])) == NULL) {
    fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
    exit (1);
  }
  if ((photcode[0].type != PHOT_PRI) && (photcode[0].type != PHOT_SEC)) {
    fprintf (stderr, "photcode %s is not a primary or secondary filter\n", argv[N]);
    exit (1);
  }

  PhotPrimary = (photcode[0].type == PHOT_PRI);
  PhotNsec = GetPhotcodeNsecfilt ();
  PhotSec = GetPhotcodeNsec (photcode[0].code);

  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;

  if (SHOW_PARAMS) {
    fprintf (stderr, "current parameter settings:\n");
    if (TimeSelect) {
      fprintf (stderr, "TimeSelect: TRUE (%s - %s)\n", sec_to_date (TSTART), sec_to_date (TSTOP));
    } else {
      fprintf (stderr, "TimeSelect: FALSE\n");
    }
    fprintf (stderr, "VERBOSE: %d, PLOTSTUFF: %d\n", VERBOSE, PLOTSTUFF);
    fprintf (stderr, "GRID_X: %d, GRID_Y: %d, BINNING: %d == Nmx: %d, Nmy: %d\n", 
	     RELPHOT_GRID_X, 
	     RELPHOT_GRID_Y, 
	     RELPHOT_GRID_BINNING, 
	     (int)(RELPHOT_GRID_X/RELPHOT_GRID_BINNING), (int)(RELPHOT_GRID_Y/RELPHOT_GRID_BINNING));

    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);
  }
}

