# include "gastro.h"

/* filename has path to GSC, strip off path, use filename with CATDIR path */

int g2mass (char *fullpath, SStars **stars, int *Nstars) {
  
  int nstar, NSTARS;
  float ra, dec, mag;
  FILE *f;

  f = fopen (fullpath, "r");
  if (f == (FILE *) NULL) {
    fprintf (stderr, "can't load catalog data\n");
    return (FALSE);
  }

  /* for now, 2Mass data is just stored in a plain file with 
     ra, dec, mag */

  nstar = *Nstars;
  NSTARS = *Nstars + 1000;
  if (*Nstars == 0) {
    ALLOCATE (stars[0], SStars, NSTARS);
  } else {
    REALLOCATE (stars[0], SStars, NSTARS);
  }

  while (fscanf (f, "%f %f %f", &ra, &dec, &mag) != EOF) {
    stars[0][nstar].X = ra;
    stars[0][nstar].Y = dec;
    stars[0][nstar].mag = mag;
    nstar ++;
    if (nstar == NSTARS) {
      NSTARS += 1000;
      REALLOCATE (stars[0], SStars, NSTARS);
    }
  }

  fclose (f);

  *Nstars = nstar;
  
  return (TRUE);
  
}
