# include "uniphot.h"

int subset_images (FITS_DB *db) {

  off_t i, Nimage, Nkeep, *keep;
  int equiv;
  Image *image;

  /* use a vtable to keep the images to be calibrated */
  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);

  Nkeep = 0;
  ALLOCATE (keep, off_t, Nimage);

  /* mark images to be calibrated */
  for (i = 0; i < Nimage; i++) {
      
    image[i].flags |= ID_IMAGE_NOCAL;

    /* select images by photcode */
    equiv = GetPhotcodeEquivCodebyCode (image[i].photcode);
    if (equiv != photcode[0].code) continue;

    /* select images by time */
    if (TimeSelect) {
      if (image[i].tzero < TSTART) continue;
      if (image[i].tzero > TSTOP) continue;
    }
    image[i].flags &= ~ID_IMAGE_NOCAL;
    keep[Nkeep] = i;
    Nkeep ++;
  }

  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, keep, Nkeep);
  return (TRUE);
}
