# include "gastro.h"

void ConfigInit (int *argc, char **argv) {
  
  char *config, *file;

  /*** 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 (0);
  }
  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);

  ScanConfig (config, "OFFSET_RADIUS",     "%lf", 0, &SEARCH_RADIUS);
  ScanConfig (config, "MIN_MATCHES",       "%d",  0, &MIN_MATCHES);
  ScanConfig (config, "DEFAULT_RADIUS",    "%lf", 0, &DEFAULT_RADIUS);
  ScanConfig (config, "MINIMUM_RADIUS",    "%lf", 0, &MINIMUM_RADIUS);
  ScanConfig (config, "MAX_ERROR",         "%lf", 0, &MAX_ERROR);
  ScanConfig (config, "MAX_NONLINEAR",     "%lf", 0, &MAX_NONLINEAR);
  ScanConfig (config, "MAX_PRECISE",       "%lf", 0, &MIN_PRECISE);
  ScanConfig (config, "CCD_PC1_1",         "%lf", 0, &CCD_PC1_1);
  ScanConfig (config, "CCD_PC2_2",         "%lf", 0, &CCD_PC2_2);
  ScanConfig (config, "CCD_PC1_2",         "%lf", 0, &CCD_PC1_2);
  ScanConfig (config, "CCD_PC2_1",         "%lf", 0, &CCD_PC2_1);
  ScanConfig (config, "ASEC_PIX",          "%lf", 0, &ASEC_PIX);
  ScanConfig (config, "NFIELD",            "%lf", 0, &NFIELD);
  ScanConfig (config, "NPOLYTERMS",        "%d",  0, &NPOLYTERMS);
  ScanConfig (config, "MMIN",              "%lf", 0, &MMIN);
  ScanConfig (config, "ROT_ZERO",          "%lf", 0, &ROT_ZERO);
  ScanConfig (config, "dROT",              "%lf", 0, &dROT);
  ScanConfig (config, "NROT",              "%d",  0, &NROT);
  ScanConfig (config, "POLAR_ALIGNMENT",   "%d",  0, &POLAR_ALIGNMENT);
  ScanConfig (config, "GSCFILE",           "%s",  0, GSCFILE);
  ScanConfig (config, "GSCDIR",            "%s",  0, GSC_DIR);
  ScanConfig (config, "POLAR_AXIS_RA",     "%lf", 0, &POLE_RA);
  ScanConfig (config, "POLAR_AXIS_DEC",    "%lf", 0, &POLE_DEC);
  ScanConfig (config, "RA_OFFSET",         "%lf", 0, &RA_OFFSET);
  ScanConfig (config, "DEC_OFFSET",        "%lf", 0, &DEC_OFFSET);
  ScanConfig (config, "LONEOS_REGIONS",    "%s",  0, LONEOS_REGION_FILE);
  ScanConfig (config, "USNO_CDROM",        "%s",  0, CDROM);
  ScanConfig (config, "ASTRO_REFCAT",      "%s",  0, REFCAT);
  ScanConfig (config, "CATDIR",            "%s",  0, CATDIR);
  ScanConfig (config, "ROUGH_ASTROMETRY",  "%s",  0, ROUGH_ASTROMETRY);
  ScanConfig (config, "PHOTCODE_FILE",     "%s",  0, PhotCodeFile);

  if (strcasecmp (ROUGH_ASTROMETRY, "header") && 
      strcasecmp (ROUGH_ASTROMETRY, "config")) {
    fprintf (stderr, "ROUGH_ASTROMETRY must be one of: header, config\n");
    exit (0);
  }
  free (config);
  free (file);
}
