# include "addstar.h"

SkyList *SkyListExistingSubset (SkyList *input, char *path) {
  
  int i, status, Nsubset, NSUBSET;
  SkyList *subset;
  struct stat filestats;
  
  Nsubset = 0;
  NSUBSET = 100;
  ALLOCATE (subset, SkyList, 1);
  ALLOCATE (subset[0].regions, SkyRegion *, NSUBSET);

  /* match the basename against the GSCRegion file names */
  for (i = 0; i < input[0].Nregions; i++) {
    status = stat (input[0].filename[i], &filestats);
    if ((status == -1) && (errno == ENOENT)) continue;
    /* give an error for other conditions? */

    subset[0].regions[Nsubset] = input[0].regions[i];
    Nsubset ++;
    CHECK_REALLOCATE (subset[0].regions, SkyRegion *, NSUBSET, Nsubset, 100);
    subset[0].Nregions = Nsubset;
  }
  return (subset);
}
