# include "astro.h"
# define NARGS 3  /* minimum is:  astro ASEC_PIX catalog */

void ahelp ()
{

  fprintf (stderr, "astro -- an astrometry routine\n");

  fprintf (stderr, "  USAGE: astro <arcsec/pix> <catalog1>, [<catalog2>,...]  \n");
  fprintf (stderr, "  optional flags:\n");
  fprintf (stderr, "  -N          -- number of input stars used (default: 100) \n");
  fprintf (stderr, "  -f RA,DEC   -- force image center to RA,DEC \n");
  fprintf (stderr, "  -R radius   -- default radius of search   (default: %f asec) \n",  DEFAULT_RADIUS);
  fprintf (stderr, "  -G N        -- grid search spacing        (default: %d ) \n", DEFAULT_NPIX);
  fprintf (stderr, "  -F n        -- quadrant for search        (default: all) \n");
  fprintf (stderr, "  -rot        -- rotated axes               (default: no) \n");
  fprintf (stderr, "                 (see below)\n");
  fprintf (stderr, "\n");
  fprintf (stderr, "  -dump -- dumps the catalog stars to stdout\n");
  fprintf (stderr, "  -help -- print this list\n");
  fprintf (stderr, "\n");
  fprintf (stderr, "\n");
  fprintf (stderr, " Effect of -F and -rot:\n");
  fprintf (stderr, "  		                            \n");
  fprintf (stderr, "  without -rot:        with -rot:       \n");
  fprintf (stderr, "  -------------        ----------       \n");                     
  fprintf (stderr, "    2  n n  1           2  e e  1       \n");
  fprintf (stderr, "       | |                 | |          \n");
  fprintf (stderr, "    e -   - e           n -   - n       \n");
  fprintf (stderr, "                                        \n");
  fprintf (stderr, "    e -   - e           n -   - n       \n");
  fprintf (stderr, "       | |                 | |          \n");
  fprintf (stderr, "    3  n n  4           3  e e  4       \n");
  fprintf (stderr, "\n"); 
  exit (0);

}

void args (argc, argv)
int     *argc;
char   **argv;
{
  
  int N;
  char line[500];

  if (N = get_argument (*argc, argv, "-dump")) {
    remove_argument (N, argc, argv);
    DUMP = TRUE;
  }
  else
    DUMP = FALSE;

  if (get_argument (*argc, argv, "-help") ||
      get_argument (*argc, argv, "-h")) {
    ahelp ();
  }

  /** optional arguments **/
  if (N = get_argument (*argc, argv, "-N")) {
    remove_argument (N, argc, argv);
    N2NUMBER = atof (argv[N]);
    remove_argument (N, argc, argv);
  }
  else {
    N2NUMBER = 100;
  }
  
  if (N = get_argument (*argc, argv, "-NIM")) {
    remove_argument (N, argc, argv);
    NIM = atof (argv[N]);
    remove_argument (N, argc, argv);
  }
  else {
    NIM = 2;
  }
  
  if (N = get_argument (*argc, argv, "-F")) {
    remove_argument (N, argc, argv);
    FLIP = atof (argv[N]);
    remove_argument (N, argc, argv);
  }
  else {
    FLIP = 0;
  }
  
  if (N = get_argument (*argc, argv, "-rot")) {
    remove_argument (N, argc, argv);
    ROTATE = TRUE;
  }
  else {
    ROTATE = FALSE;
  }
  
  if (N = get_argument (*argc, argv, "-f")) {
    FORCE = TRUE;
    remove_argument (N, argc, argv);
    F_RA = atof (argv[N]);
    remove_argument (N, argc, argv);
    F_DEC = atof (argv[N]);
    remove_argument (N, argc, argv);
  }
  else {
    FORCE = FALSE;
  }
  
  if (N = get_argument (*argc, argv, "-R")) {
    remove_argument (N, argc, argv);
    RADIUS = atof (argv[N]);
    remove_argument (N, argc, argv);
  }
  else {
    RADIUS = DEFAULT_RADIUS;
  }
  
  if (N = get_argument (*argc, argv, "-G")) {
    remove_argument (N, argc, argv);
    NPIX = atof (argv[N]);
    remove_argument (N, argc, argv);
  }
  else {
    NPIX = DEFAULT_NPIX;
  }
  
  if (*argc < NARGS) {
    fprintf (stderr, "USAGE: astro <arcsec/pix> <catalog1>, [<catalog2>,...]  \n");
    fprintf (stderr, "  enter filenames, followed by EOF\n");
    exit (0);
  }
  
  ASEC_PIX = atof (argv[1]);
  remove_argument (1, argc, argv);
  if (ASEC_PIX < 0.01) {
    fprintf (stderr, "%f arcsec / pixel, is this really true?\n", 
	     ASEC_PIX);
    fscanf (stdin, "%s", line);
    if (strcasecmp(line, "y") || strcasecmp(line, "yes"))
      exit (0);
  }
  if (ASEC_PIX > 5) {
    fprintf (stderr, "WARNING: your image may have too large\n");
    fprintf (stderr, "         a field to be well modeled with\n");
    fprintf (stderr, "         a linear astrometric solution\n");
  }
  
  
}

