# include "addstar.h"

/* read ASCII file with ref star data */
Stars *grefstars (char *file, int photcode, unsigned 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;

    InitStar (&stars[N]);

    dparse (&stars[N].average.R,  1, line);
    dparse (&stars[N].average.D,  2, line);
    stars[N].average.R = ohana_normalize_angle (stars[N].average.R);

    fparse (&stars[N].measure.M,  3, line);
    fparse (&stars[N].measure.dM, 4, line);

    stars[N].measure.photcode = photcode;

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