# include "photdbc.h"

int args (int argc, char **argv) {

  int N;

  VERBOSE = FALSE;
  if ((N = get_argument (argc, argv, "-v"))) {
    VERBOSE = TRUE;
    remove_argument (N, &argc, argv);
  }

  SHOW_PARAMS = FALSE;
  if ((N = get_argument (argc, argv, "-params"))) {
    remove_argument (N, &argc, argv);
    SHOW_PARAMS = TRUE;
  }

  ExcludeByInstMag = FALSE;
  if ((N = get_argument (argc, argv, "-instmag"))) {
    remove_argument (N, &argc, argv);
    ExcludeByInstMag = TRUE;
    remove_argument (N, &argc, argv);
    INST_MAG_MIN = atof(argv[N]);
    remove_argument (N, &argc, argv);
    INST_MAG_MAX = atof(argv[N]);
  }

  ExcludeByMaxMinMag = FALSE;
  if ((N = get_argument (argc, argv, "-maxminmag"))) {
    remove_argument (N, &argc, argv);
    ExcludeByMaxMinMag = TRUE;
    remove_argument (N, &argc, argv);
    MAX_MIN_MAG = atof(argv[N]);
  }

  /* specify portion of the sky */
  REGION.Rmin = 0;
  REGION.Rmax = 360;
  REGION.Dmin = -90;
  REGION.Dmax = +90;
  if ((N = get_argument (argc, argv, "-region"))) {
    remove_argument (N, &argc, argv);
    REGION.Rmin = atof (argv[N]);
    remove_argument (N, &argc, argv);
    REGION.Rmax = atof (argv[N]);
    remove_argument (N, &argc, argv);
    REGION.Dmin = atof (argv[N]);
    remove_argument (N, &argc, argv);
    REGION.Dmax = atof (argv[N]);
    remove_argument (N, &argc, argv);

    if (REGION.Rmin == REGION.Rmax) {
      fprintf (stderr, "ERROR: selected region is ill-defined: Rmin == Rmax\n");
      exit (2);
    }
    if (REGION.Dmin == REGION.Dmax) {
      fprintf (stderr, "ERROR: selected region is ill-defined: Dmin == Dmax\n");
      exit (2);
    }
  }

  if (argc != 2) {
    fprintf (stderr, "USAGE: photdbc (output)\n");
    exit (2);
  } 

  if ((REGION.Rmin == 0) && (REGION.Rmax == 360) && (REGION.Dmin == -90) && (REGION.Dmax == +90)) {
    int i;
    fprintf (stderr, "you have requested a copy of the entire sky in one pass\n");
    fprintf (stderr, "this could be a time consuming operation.  type Ctrl-C within 5 seconds to cancel\n");
    for (i = 5; i > 0; i--) {
      fprintf (stderr, "%d.. ", i);
      usleep (1000000);
    }
    fprintf (stderr, "\n");
  }

  return (TRUE);
}

/**

 this program takes an existing DVO database and makes a copy, applying a number of optional
 filters in the process.  

 photdbc (output)

 allowed filters / restrictions include:

 -region ra dec ra dec : limit operation to the specified region 
 -join                 : join measurements between stars using JOIN_RADIUS
 -ccdregion X Y X Y    : only keep detections within the specified detector region
                         (can this be limited to specific photcodes? cameras? detectors?)
 -photcode_limits code Mmin Mmax : allow multiples of these

 SIGMA_MAX
 NMEAS_MIN
 INST_MAG_MAX
 INST_MAG_MIN

**/
