# include "addstar.h"

/* set specific options based on the image collection */
int ImageOptions (AddstarClientOptions *options, Image *images, int Nimages) {

  int i, equivPhotcode;
  float maxError;
  PhotCode *photcode;

  // set the radius to the maximum error circle
  if (options[0].radius == 0) {
    maxError = 0;
    for (i = 0; i < Nimages; i++) {
      maxError = MAX (maxError, 0.02 * images[i].cerror);
    }
    options[0].radius = options[0].Nsigma * maxError;
  }     

  // check that all images have the same equiv photcode and save it
  equivPhotcode = 0;

  for (i = 0; i < Nimages; i++) {
    /* MOSAIC_PHU images do not have a photcode */
    if (!strcmp (&images[0].coords.ctype[4], "-DIS")) continue;

    photcode = GetPhotcodebyCode (images[i].source);

    if (equivPhotcode) {
      if (equivPhotcode != photcode[0].equiv) {
	fprintf (stderr, "ERROR: mismatch in equiv photcode values\n");
	exit (2);
      }
    } else {
      equivPhotcode = photcode[0].equiv;
    }
  }
  options[0].photcode = equivPhotcode;
  return (TRUE);
}
