# 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;

    /* 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 */
    FitChip (raw, ref, Nstars, &image[i].coords);

    free (raw);
    free (ref);
  }

  return (TRUE);
}

