# include "skycells.h"
static void help (void);

int args_skycells (int argc, char **argv) {
  
  int i, N;
  char *ptr;

  /* check for help request */
  if (get_argument (argc, argv, "-help") ||
      get_argument (argc, argv, "-h")) {
    help ();
  }

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

  /* what type of output files? */
  MODE = SQUARES;
  if ((N = get_argument (argc, argv, "-triangles"))) {
    MODE = TRIANGLES;
    remove_argument (N, &argc, argv);
  }

  /* pixel scale (arcsec/pixel) */
  SCALE = 1.0;
  if ((N = get_argument (argc, argv, "-scale"))) {
    remove_argument (N, &argc, argv);
    SCALE = atof (argv[N]);
    remove_argument (N, &argc, argv);
  }

  /* max number of skycells kept in memory */
  NMAX = 200000;
  if ((N = get_argument (argc, argv, "-nmax"))) {
    remove_argument (N, &argc, argv);
    NMAX = atof (argv[N]);
    remove_argument (N, &argc, argv);
  }

  /* max number of skycells kept in memory */
  NX_SUB = NY_SUB = 1;
  if ((N = get_argument (argc, argv, "-nx"))) {
    remove_argument (N, &argc, argv);
    NX_SUB = atof (argv[N]);
    remove_argument (N, &argc, argv);
  }
  if ((N = get_argument (argc, argv, "-ny"))) {
    remove_argument (N, &argc, argv);
    NY_SUB = atof (argv[N]);
    remove_argument (N, &argc, argv);
  }

  if (argc == 2) {
    strtol (argv[1], &ptr, 10);
    if (*ptr == 0) return (TRUE);
  }

  fprintf (stderr, "USAGE: skycells (level) [-triangles] [-scale arcsec/pix] [-nmax Max Cells in memory] [-nx (Nx cells)] [-ny (Ny cells)]\n");
  exit (2);
}

static void help () {

  fprintf (stderr, "USAGE\n");
  fprintf (stderr, "  skycells\n\n");

  fprintf (stderr, "  -v                    	  : verbose mode\n");
  fprintf (stderr, "  -help                 	  : this list\n");
  fprintf (stderr, "  -h                    	  : this list\n\n");
  exit (2);
}
