Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h	(revision 38315)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h	(revision 38316)
@@ -141,4 +141,8 @@
   int *NexpPS1;		      // count of PS1 exposure (chip) measurements for this secfilt
   int *haveUbercal;	      // does this secfilt have any ubercal data?
+
+  int *tessID;		      // tess,proj,skycell to use for warp and diff analysis
+  int *projID;
+  int *skycellID;
 
   float *minUbercalDist;
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c	(revision 38315)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c	(revision 38316)
@@ -117,4 +117,9 @@
     results->havePS1[i] = 0;
     results->haveUbercal[i] = 0;
+
+    results->tessID[i]    = 0;
+    results->projID[i]    = 0;
+    results->skycellID[i] = 0;
+
     results->minUbercalDist[i] = 1000;
 
@@ -156,4 +161,8 @@
     ALLOCATE (results->haveUbercal,    int, results->Nsecfilt);
 
+    ALLOCATE (results->tessID,         int, results->Nsecfilt);
+    ALLOCATE (results->projID,         int, results->Nsecfilt);
+    ALLOCATE (results->skycellID,      int, results->Nsecfilt);
+
     ALLOCATE (results->minUbercalDist, float, results->Nsecfilt);
 
@@ -185,8 +194,16 @@
     results->psfQfMax = NULL;
     results->psfQfPerfMax = NULL;
+
+    results->Nmeas = NULL;
+    results->NmeasGood = NULL;
     results->Next = NULL;
     results->NexpPS1 = NULL;
     results->havePS1 = NULL;
     results->haveUbercal = NULL;
+
+    results->tessID = NULL;
+    results->projID = NULL;
+    results->skycellID = NULL;
+
     results->minUbercalDist = NULL;
   }
@@ -200,4 +217,26 @@
   FREE (results->psfqfperf_list);
   FREE (results->stargal_list);
+
+  FREE (results->havePS1);
+  FREE (results->haveSYN);
+  FREE (results->needSYN);
+  FREE (results->measSYN);
+  FREE (results->minSYN );
+
+  FREE (results->psfQfMax);
+  FREE (results->psfQfPerfMax);
+
+  FREE (results->Nmeas);
+  FREE (results->NmeasGood);
+  FREE (results->Next);
+  FREE (results->NexpPS1);
+  FREE (results->havePS1);
+  FREE (results->haveUbercal);
+
+  FREE (results->tessID);
+  FREE (results->projID);
+  FREE (results->skycellID);
+
+  FREE (results->minUbercalDist);
 }
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c	(revision 38315)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c	(revision 38316)
@@ -644,4 +644,5 @@
 // somewhat simplified relative to chip-photometry:
 // * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr
+// analysis is done on flux, not mags (as the faintest objects will be nearly insignificant)
 int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results) {
 
@@ -649,7 +650,10 @@
 
   // we are guaranteed to have average, measure, secfilt
-  Average *average = &catalog[0].average[ave];
-  Measure *measure = &catalog[0].measure[measureOffset];
-  SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt];
+  Average *average  = &catalog[0].average[ave];
+  Measure *measure  = &catalog[0].measure[measureOffset];
+  SecFilt *secfilt  = &catalog[0].secfilt[ave*Nsecfilt];
+  char *measureRank = &catalog[0].measureRank[measureOffset];
+
+  off_t measureOffset = average->measureOffset;
 
   off_t k;
@@ -662,19 +666,18 @@
   }
 
-  // for a diff db, we just want primary, if available or not
-  int priTessID, priProjID, priSkycellID;
+  // for a diff db, we just want primary, if available or not. for warp we want to use the
+  // skycell which provided the stack best entry
+  int tessID, projID, skycellID;
   if (IS_DIFF_DB) {
-    get_tess_ids(&priTessID, &priProjID, &priSkycellID, average[0].R, average[0].D);
-  }
-
+    get_tess_ids(&tessID, &projID, &skycellID, average[0].R, average[0].D);
+  }
   for (Nsec = 0; Nsec < Nsecfilt; Nsec++) {
-    // I need to restrict the measurements coming only from the same skycell as the secfilt values
-    // if we cannot make that association, skip this set of warps
-    int stkTessID, stkProjID, stkSkycellID;
-    
     if (!IS_DIFF_DB) {
       myAssert (secfilt[Nsec].stackBestOff <= Nmeasure, "stackBestOff out of range");
       if (!FindImageSkycellID (secfilt[Nsec].stackBestOff, cat, &stkTessID[Nsec], &stkProjID[Nsec], &stkSkycellID[Nsec])) continue;
     }
+    results->tessID[Nsec]    = tessID;
+    results->projID[Nsec]    = projID;
+    results->skycellID[Nsec] = skycellID;
   }
 
@@ -694,5 +697,5 @@
 
     results->Nmeas[Nsec] ++;
-    if (measure[k].psfQFperf > 0.85) results->NwarpGood[Nsec] ++;
+    if (measure[k].psfQFperf > 0.85) results->NmeasGood[Nsec] ++;
 
     measure[k].dbFlags &= ~ID_MEAS_WARP_USED;
@@ -715,4 +718,5 @@
     }
 
+    off_t meas = measureOffset + k;
     if (getImageEntry (meas, cat) < 0) {
       // measurements without an image are either external reference photometry or
@@ -792,5 +796,5 @@
     }
     int minRank = (Nranking > 0) ? results->psfData[Nsec].ranking[0] : 10;
-    markMeasureByRanking (&results->psfData[Nsec], measure, minRank, IID_MEAS_WARP_USED);
+    markMeasureByRanking (&results->psfData[Nsec], measure, minRank, ID_MEAS_WARP_USED);
 
     // if too few valid measurements meet the minimum criteria, go to the next entry
@@ -829,4 +833,6 @@
   off_t k;
 
+  myAbort ("this function makes no sense");
+
   float psfQFmax     = 0.0;
   float psfQFperfmax = 0.0;
