# include "addstar.h"

/* read ASCII file with ref star data */
Stars *grefstars (char *file, int photcode, int *Nstars) {

  FILE *f;
  int N, NSTARS;
  Stars *stars;
  char line[256];

  /* open file */
  f = fopen (file, "r");
  if (f == NULL) Shutdown ("can't read data from %s", file);

  NSTARS = 100;
  ALLOCATE (stars, Stars, NSTARS);

  /* read in stars line-by-line */
  for (N = 0; scan_line (f, line) != EOF; N++) {
    stripwhite (line);
    if (line[0] == 0) continue;
    if (line[0] == '#') continue;
    dparse (&stars[N].R,  1, line);
    dparse (&stars[N].D,  2, line);
    dparse (&stars[N].M,  3, line);
    dparse (&stars[N].dM, 4, line);
    while (stars[N].R < 0.0) stars[N].R += 360.0;
    while (stars[N].R >= 360.0) stars[N].R -= 360.0;
    stars[N].t = 0;
    stars[N].code = photcode;
    stars[N].found = FALSE;
    stars[N].detID   = 0;
    stars[N].imageID = 0;

    stars[N].X  = 0;
    stars[N].Y  = 0;
    stars[N].fx = 0;
    stars[N].fy = 0;
    stars[N].df = 0;

    CHECK_REALLOCATE (stars, Stars, NSTARS, N+1, 100);
  }
  *Nstars = N;
  return (stars);
}

/* stars.found is set here to FALSE.
   find_match_refstars uses stars.found to identify the seq number of the
   star which is found.  it requires an initial value of -1 XXX
*/
