# include "dvoImageExtract.h"

/* given image, find catalog images which overlap it */
int *SelectImages (char *filename, Image *images, int Nimages, int *Nmatch) {
  
  int i, Nchar;
  int NMATCH, nmatch, *match;

  /* matches here are only based on string comparisons */

  /* match represents the subset of matched images */
  nmatch = 0;
  NMATCH = 20;
  ALLOCATE (match, int, NMATCH);

  /* setup links for mosaic WRP and DIS entries */
  BuildChipMatch (images, Nimages);

  Nchar = strlen (filename);

  for (i = 0; i < Nimages; i++) {

    if (strncmp (images[i].name, filename, Nchar)) continue;

    match[nmatch] = i;
    nmatch ++;
    if (nmatch == NMATCH) {
      NMATCH += 20;
      REALLOCATE (match, int, NMATCH);
    }
  }  

  if (VERBOSE) fprintf (stderr, "found %d matching images\n", nmatch);

  *Nmatch = nmatch;
  return (match);
}
