# include "uniphot.h"

int subset_images (FITS_DB *db) {

  int    i, Nimage, equiv;
  int    Nkeep, *keep;
  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, int, 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);
}
