# include "astro.h"

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

  int x, y, N, dx, Nborder;
  double max;
  Buffer *buf;
  int VERBOSE;

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

  Nborder = 3;
  if ((N = get_argument (argc, argv, "-border"))) {
    remove_argument (N, &argc, argv);
    Nborder  = atof(argv[N]);
    remove_argument (N, &argc, argv);
  }
  Nborder = MAX (Nborder, 1);
  
  max = 60000;
  if ((N = get_argument (argc, argv, "-sat"))) {
    remove_argument (N, &argc, argv);
    max  = atof(argv[N]);
    remove_argument (N, &argc, argv);
  }
  
  if ((argc != 4) && (argc != 5)) {
    gprint (GP_ERR, "USAGE: star (buffer) x y [dx] [-border N] [-sat cnts]\n");
    gprint (GP_ERR, " dx is the aperture diameter, but is adjusted up to the next odd number\n");
    return (FALSE);
  }
  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);

  dx = 11;
  x = atof (argv[2]);
  y = atof (argv[3]);
  if (argc == 5) {
    dx = atof (argv[4]);
  }

  get_aperture_stats (&buf[0].matrix, x, y, dx, Nborder, max, VERBOSE);
  
  return (TRUE);
}

