# include "addstar.h"
#include <sys/time.h>
#include <time.h>

Stars *gstars (char *file, int *Nstars) {

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

  /* open file */
  f = fopen (file, "r");
  if (f == NULL) {
    fprintf (stderr, "ERROR: can't read data from %s\n", file);
    Shutdown ();
  }

  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].dophot = 0;
    stars[N].found = -1;
    if (N == NSTARS - 1) {
      NSTARS += 100;
      REALLOCATE (stars, Stars, NSTARS);
    }
  }
  *Nstars = N;
  return (stars);
}

