# include "relastro.h"

void FitMosaic (StarData *raw, StarData *ref, int Nmatch, Coords *coords) {

  int i;
  CoordFit *fit;

  fit = fit_init (coords[0].Npolyterms);
  for (i = 0; i < Nmatch; i++) {
    if (raw[i].mask) continue;
    fit_add (fit, raw[i].L, raw[i].M, ref[i].P, ref[i].Q, 1.0);
  }
  fit_eval (fit);
  fit_apply_coords (fit, coords);
  fit_free (fit);
  /* FitChip and FitSimple update the coords in different ways? maybe not... */
}

/* XXX the supporting fitting functions are not quite right
   I probably need to apply the projection and then do the fit 
   to L,M.  I also need to incorporate the transformations 
   determined for psastro */


/* in the simple case, we only have three coord systems of interest:
   R,D : the sky
   P,Q : the tangent plane
   X,Y : the chip

   R,D -> P,Q (projection)
   P,Q -> X,Y (polynomial transformation)
*/

/* XXX I'm not using the errors at all : this could at least be done with the dMag values */

   
