# include "relastro.h"

int UpdateChips (Catalog *catalog, int Ncatalog) {

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

  image = getimages (&Nimage);

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

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

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

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

    FitChip (raw, ref, Nstars, &image[i].coords);

    free (raw);
    free (ref);
  }

  return (TRUE);
}

