# include "astro.h"

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

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

  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");
    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]);
  }

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

