# include "addstar.h"

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

  char *config, *file;
  char RadiusWord[80];
  char PhotCodeFile[256];

  /*** load configuration info ***/
  file = SelectConfigFile (argc, argv, "ptolemy");
  config = LoadConfigFile (file);
  if (config == (char *) NULL) {
    fprintf (stderr, "ERROR: can't find configuration file %s\n", file);
    if (file != (char *) NULL) free (file);
    exit (1);
  }
  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);

  ScanConfig (config, "RADIUS",                 "%s", 0,  RadiusWord);
  if (!strcasecmp (RadiusWord, "header")) {
    DEFAULT_RADIUS = 0;
  } else {
    DEFAULT_RADIUS = atof (RadiusWord);
  }

  XMIN = XMAX = YMIN = YMAX = 0;
  ScanConfig (config, "NSIGMA",                 "%lf", 0, &NSIGMA);
  ScanConfig (config, "XOVERSCAN",              "%d", 0, &XOVERSCAN);
  ScanConfig (config, "YOVERSCAN",              "%d", 0, &YOVERSCAN);
  ScanConfig (config, "ADDSTAR_XMIN",           "%d", 0, &XMIN);
  ScanConfig (config, "ADDSTAR_XMAX",           "%d", 0, &XMAX);
  ScanConfig (config, "ADDSTAR_YMIN",           "%d", 0, &YMIN);
  ScanConfig (config, "ADDSTAR_YMAX",           "%d", 0, &YMAX);

  ScanConfig (config, "IMAGE_CATALOG",          "%s", 0, ImageCat);
  ScanConfig (config, "IMAGE_CATALOG_TEMPLATE", "%s", 0, ImageTemplate);
  ScanConfig (config, "CATALOG_TEMPLATE",       "%s", 0, CatTemplate);
  ScanConfig (config, "GSCFILE",                "%s", 0, GSCFILE);
  ScanConfig (config, "CATDIR",                 "%s", 0, CATDIR);
  ScanConfig (config, "MIN_SN_FSTAT",           "%lf", 0, &SNLIMIT);
  ScanConfig (config, "PHOTCODE_FILE",          "%s", 0, PhotCodeFile);

  ScanConfig (config, "DATE-KEYWORD",           "%s", 0, DateKeyword);
  ScanConfig (config, "DATE-MODE",              "%s", 0, DateMode);
  ScanConfig (config, "UT-KEYWORD",             "%s", 0, UTKeyword);
  ScanConfig (config, "MJD-KEYWORD",            "%s", 0, MJDKeyword);
  ScanConfig (config, "JD-KEYWORD",             "%s", 0, JDKeyword);

  ScanConfig (config, "EXPTIME-KEYWORD",        "%s", 0, ExptimeKeyword);
  ScanConfig (config, "AIRMASS-KEYWORD",        "%s", 0, AirmassKeyword);
  ScanConfig (config, "CCDNUM-KEYWORD",         "%s", 0, CCDNumKeyword);

  if (!LoadPhotcodes (PhotCodeFile)) {
    fprintf (stderr, "error loading photcodes\n");
    exit (1);
  }

  free (config);
  free (file);

}
