# include "addstar.h"
# define LOAD_ALLSKY 0
# define LOAD_DR2    1

Stars *greference (char *Refcat, SkyRegion *region, int photcode, unsigned int *nstars) {

  unsigned int Nstars;
  Stars *stars;

  if (VERBOSE) fprintf (stderr, "loading reference catalog data from %s\n", Refcat); 
  if (VERBOSE) fprintf (stderr, "full region: %f - %f, %f - %f\n", region[0].Rmin, region[0].Rmax, region[0].Dmin, region[0].Dmax);

  Nstars = 0;
  stars = NULL;

  /* get stars from USNO for the given region */
  if (!strcasecmp (Refcat, "USNO")) {
    stars = getusno (region, photcode, &Nstars);
  }

  /* get stars from the USNO B catalog for the given region */
  if (!strcasecmp (Refcat, "USNOB")) {
    stars = getusnob (region, photcode, &Nstars);
  }

  /* get stars from the USNO B catalog for the given region */
  if (!strcasecmp (Refcat, "TYCHO")) {
    stars = gettycho (region, photcode, &Nstars);
  }

  /* get stars from HST GSC for the given region */
  if (!strcasecmp (Refcat, "GSC")) {
    stars = getgsc (region, &Nstars);
  }
  
  /* get stars from 2MASS for the given region */
  if (!strcasecmp (Refcat, "2MASS")) {
    // stars = get2mass (region, photcode, LOAD_ALLSKY, &Nstars);
    fprintf (stderr, "2MASS load via addstar is deprecated: use load2mass\n");
    exit (2);
  }
  
  /* get stars from 2MASS for the given region */
  if (!strcasecmp (Refcat, "2MASS-ALLSKY")) {
    // stars = get2mass (region, photcode, LOAD_ALLSKY, &Nstars);
    fprintf (stderr, "2MASS load via addstar is deprecated: use load2mass\n");
    exit (2);
  }
  
  /* get stars from 2MASS for the given region */
  if (!strcasecmp (Refcat, "2MASS-DR2")) {
    // stars = get2mass (region, photcode, LOAD_DR2, &Nstars);
    fprintf (stderr, "2MASS load via addstar is deprecated: use load2mass\n");
    exit (2);
  }
  
  if (VERBOSE && (Nstars == 0)) fprintf (stderr, "no ref objects in region %s\n", region[0].name);

  *nstars = Nstars;
  return (stars);

}
