# include "astro.h"
# define D_NSTARS 1000

Stars *get_catalog_stars (ra, dec, mag, Ncat, RA, DEC, dRA, dDEC, Nstars)
double *ra;
double *dec;
double *mag;
int     Ncat;
double RA, DEC, dRA, dDEC;
int   *Nstars;
{

  int i, j, NSTARS;
  Stars  *stars;

  NSTARS = D_NSTARS;
  ALLOCATE (stars, Stars, NSTARS);
  fprintf (stderr,"%f %f  %f %f\n", RA, DEC, dRA, dDEC);

  j = 0;
  for (i = 0; i < Ncat; i++) {
    if ((ra[i]  > RA  - NIM*dRA)  && (ra[i]  < RA  + NIM*dRA) &&
	(dec[i] > DEC - NIM*dDEC) && (dec[i] < DEC + NIM*dDEC)) {
      stars[j].X = ra[i];
      stars[j].Y = dec[i];
      stars[j].mag = mag[i];
      j++;
      if (j == NSTARS - 1) {
	NSTARS += D_NSTARS;
	REALLOCATE (stars, Stars, NSTARS);
      }
    }
  }

  *Nstars = j;
  fprintf (stderr, "using %d stars from catalog\n", j);

  return (stars);

}
