# include "relastro.h"

int UpdateMosaic (Catalog *catalog, int Ncatalog) {

  /* we can measure new image parameters for each mosaic independently */
  int i, Nimage, Nstars;
  Image *image;
  StarData *raw, *ref;

  image = getimages (&Nimage);

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

    /* skip all except DIS images */
    if (strcmp(&image[i].coords.ctype[4], "-DIS")) continue;

    /* XXX I probably need modes for getImageRaw/Ref to distinguish SIMPLE, CHIP, MOSAIC */

    /* convert measure coordinates to raw entries */
    raw = getImageRaw (catalog, Ncatalog, i, &Nstars, TRUE);

    /* convert average coordinates to ref entries */
    ref = getImageRef (catalog, Ncatalog, i, &Nstars, TRUE);

    /* XXX grab this code from mosastro */
    /* XXX check that it matches psastro */
    /* XXX this may need a 'mosaic' and 'non-mosaic' version */
    FitMosaic (raw, ref, Nstars, &image[i].coords);

    free (raw);
    free (ref);
  }

  return (TRUE);
}

