Index: /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/initialize_fiximids.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/initialize_fiximids.c	(revision 35591)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/initialize_fiximids.c	(revision 35592)
@@ -5,10 +5,14 @@
     fprintf (stderr, "  options:\n");
     fprintf (stderr, "    -v : verbose mode\n");
+    fprintf (stderr, "    -cpt n0000/0000.00.cpt : only repair this cpt file \n");
+    fprintf (stderr, "    -region Rmin Rmax Dmin Dmax : only repair this region\n");
     fprintf (stderr, "    -update : actually write results to detections tables\n");
-    fprintf (stderr, "    -parallel : run in parallel mode\n");
+    fprintf (stderr, "    -parallel : run in parallel mode\n\n");
+
     fprintf (stderr, "    -h     : this help list\n");
     fprintf (stderr, "    -help  : this help list\n");
     fprintf (stderr, "    --h    : this help list\n");
     fprintf (stderr, "    --help : this help list\n");
+    
     fprintf (stderr, "    Note that the dvo db can be specified by -D CATDIR (directory)\n");
     exit (2);
@@ -170,4 +174,11 @@
   }
 
+  SINGLE_CPT = NULL;
+  if ((N = get_argument (argc, argv, "-cpt"))) {
+    remove_argument (N, &argc, argv);
+    SINGLE_CPT = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
   // region of interest
   UserPatch.Rmin = 0;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/load_images_fiximids.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/load_images_fiximids.c	(revision 35591)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/load_images_fiximids.c	(revision 35592)
@@ -1,13 +1,10 @@
 # include "fiximids.h"
 
-// array of mosaic definition structures
-static off_t   Nmosaic;
-static Mosaic *mosaic;
+off_t Nimage;
+e_time *startImage;
+e_time *stopImage;
+short *photcodeImage;
 
-// list of mosaic associated with each image  
-static off_t    Nmosaic_for_images; // number of images (for off_ternal checks)
-static off_t    *mosaic_for_images; // array of: image -> mosaic
-
-Image *load_images_fiximids (FITS_DB *db, off_t *Nimage) {
+Image *load_images_fiximids (FITS_DB *db, off_t *N) {
 
   Image *image;
@@ -25,4 +22,6 @@
   }
 
+  // XXX init lookup tables
+
   fprintf (stderr, "loaded "OFF_T_FMT" images\n", *Nimage);
 
@@ -33,7 +32,7 @@
 // This code is copied from relastro/src/MosaicOps.c
 
-off_t getMosaicByTimes (unsigned int start, unsigned int stop, unsigned int *startMos, unsigned int *stopMos, off_t *indexMos) {
+off_t FindImageID (e_time time, short photcode) {
 
-  // use bisection to find the overlapping mosaic
+  // use bisection to find the overlapping imagea
 
   off_t Nlo, Nhi, N;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/update_catalog_fiximids.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/update_catalog_fiximids.c	(revision 35591)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/update_catalog_fiximids.c	(revision 35592)
@@ -7,35 +7,31 @@
 
   found = 0;    
-  for (i = 0; i < catalog[0].Naverage; i++) {
+  for (i = 0; i < catalog[0].Nmeasure; i++) {
+    
+    // only do PS1 / GPC1 photcodes?
+    // XXX if (catalog[0].measure[i].photcode < 10000) continue;
+    // XXX if (catalog[0].measure[i].photcode > 10600) continue;
 
-    off_t m = catalog[0].average[i].measureOffset;
-    for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
-      off_t ID = catalog[0].measure[m].imageID;
-      if (ID <= 0) continue; // detections with imageID == 0 do not have a valid image (eg, ref photcode)
+    // we have a measure with a given photcode and time:
+    short photcode = catalog[0].measure[i].photcode;
+    e_time time = catalog[0].measure[i].t;
 
-      // XXX only do GPC1 data for now
-      catalog[0].measure[m].pltscale = pltScale;
-      if (catalog[0].measure[m].photcode < 10000) continue;
-      if (catalog[0].measure[m].photcode > 10600) continue;
-      
-      // index[ID] = seqN
+    off_t imageID = FindImageID (time, photcode);
+    if (imageID <= 0) continue; // detections with imageID == 0 do not have a valid image (eg, ref photcode)
 
-      off_t seq = index[ID];
+    if (imageID == catalog[0].measure[i].imageID) {
+      // existing image ID is valid
+      Nvalid ++;
+      onImage[imageID] ++;
+      continue;
+    }
 
-      Mosaic *mosaic = getMosaicForImage(seq);
-      Coords *coords = &image[seq].coords;
-      Coords *mosaicCoords = mosaic ? &mosaic->coords : NULL;
+    // existing image ID is NOT valid
+    catalog[0].measure[i].imageID = imageID;
+    Ninvalid ++;
+    onImage[imageID] ++;
+    continue;
 
-      double Xccd = catalog[0].measure[m].Xccd;
-      double Yccd = catalog[0].measure[m].Yccd;
-      
-      fiximids_local_astrometry (&posAngle, &pltScale, Xccd, Yccd, mosaicCoords, coords);
-
-      catalog[0].measure[m].posangle = ToShortDegrees(posAngle);
-      catalog[0].measure[m].pltscale = pltScale;
-      myAssert(isfinite(catalog[0].measure[m].posangle), "oops: fiximids made a nan");
-      myAssert(isfinite(catalog[0].measure[m].pltscale), "oops: fiximids made a nan");
-      found ++;
-    }
+    found ++;
   }
 
@@ -45,67 +41,2 @@
 }
 
-// this is basically a re-write / adaptation of pmSourceLocalAstrometry
-// posangle in degrees, plate scale in arcseconds/pixel
-int fiximids_local_astrometry (float *posAngle, float *pltScale, double x, double y, Coords *mosaic, Coords *coords) {
-
-  double Lx, Mx, Po, Qo, Px, Qx, Py, Qy;
-
-  // calculate the astrometry for the coordinate of interest
-  XY_to_LM (&Lx, &Mx, x,       y,       coords);
-  if (mosaic) {
-    XY_to_LM (&Po, &Qo, Lx,      Mx,      mosaic);
-  } else {
-    Po = Lx;
-    Qo = Mx;
-  }
-
-  XY_to_LM (&Lx, &Mx, x + 1.0, y,       coords);
-  if (mosaic) {
-    XY_to_LM (&Px, &Qx, Lx,      Mx,      mosaic);
-  } else {
-    Px = Lx;
-    Qx = Mx;
-  }
-
-  XY_to_LM (&Lx, &Mx, x,       y + 1.0, coords);
-  if (mosaic) {
-    XY_to_LM (&Py, &Qy, Lx,      Mx,      mosaic);
-  } else {
-    Py = Lx;
-    Qy = Mx;
-  }
-
-  // XXX units for the resulting Tangent Plane coordinates??
-
-  double dPdX = Px - Po;
-  double dPdY = Py - Po;
-
-  double dQdX = Qx - Qo;
-  double dQdY = Qy - Qo;
-
-  double pltScale_x = hypot(dPdX, dQdX);
-  double pltScale_y = hypot(dPdY, dQdY);
-  *pltScale = 3600.0*0.5*(pltScale_x + pltScale_y);
-
-  double posAngle_x, posAngle_y;
-  double crossProduct = dPdX * dQdY - dPdY * dQdX;
-  if  (crossProduct > 0.) {
-    *pltScale *= -1.0;
-    posAngle_x = atan2 (dQdX, dPdX);
-    posAngle_y = atan2 (dQdY, dPdY) - M_PI_2;
-  } else {
-    posAngle_x = atan2 (dQdX, -dPdX);
-    posAngle_y = atan2 (dQdY,  dPdY) - M_PI_2;
-  }
-
-  // with errors, these may end up on opposite sides of the M_PI boundary.  
-  if (posAngle_x - posAngle_y > M_PI) {
-    posAngle_y += 2.0 * M_PI;
-  }
-  if (posAngle_y - posAngle_x > M_PI) {
-    posAngle_x += 2.0 * M_PI;
-  }
-  *posAngle = 0.5*(posAngle_x + posAngle_y)*DEG_RAD;
-
-  return TRUE;
-}
Index: /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/update_dvo_fiximids.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/update_dvo_fiximids.c	(revision 35591)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/uniphot/src/update_dvo_fiximids.c	(revision 35592)
@@ -120,6 +120,7 @@
 
     char tmpline[1024];
-    if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
-    if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",         command); 		     strcpy (command, tmpline); }
+    if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",                  command); strcpy (command, tmpline); }
+    if (SINGLE_CPT)    { snprintf (tmpline, 1024, "%s -cpt %s", SINGLE_CPT, command); strcpy (command, tmpline); }
+    if (UPDATE)        { snprintf (tmpline, 1024, "%s -update",             command); strcpy (command, tmpline); }
 
     if (PARALLEL_MANUAL) continue;
