Index: /trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- /trunk/Ohana/src/relphot/include/relphot.h	(revision 37906)
+++ /trunk/Ohana/src/relphot/include/relphot.h	(revision 37907)
@@ -191,4 +191,5 @@
 
 int SET_MREL_VERSION;
+int IS_DIFF_DB;
 
 double MAG_LIM;
Index: /trunk/Ohana/src/relphot/src/args.c
===================================================================
--- /trunk/Ohana/src/relphot/src/args.c	(revision 37906)
+++ /trunk/Ohana/src/relphot/src/args.c	(revision 37907)
@@ -64,4 +64,10 @@
   }
 
+  IS_DIFF_DB = FALSE;
+  if ((N = get_argument (argc, argv, "-is-diff-db"))) {
+    remove_argument (N, &argc, argv);
+    IS_DIFF_DB = TRUE;
+  }
+
   USE_FULL_OVERLAP = TRUE;
   if ((N = get_argument (argc, argv, "-sloppy-image-overlap"))) {
@@ -499,4 +505,10 @@
     UserPatch.Dmax = atof (argv[N]);
     remove_argument (N, &argc, argv);
+  }
+
+  IS_DIFF_DB = FALSE;
+  if ((N = get_argument (argc, argv, "-is-diff-db"))) {
+    remove_argument (N, &argc, argv);
+    IS_DIFF_DB = TRUE;
   }
 
Index: /trunk/Ohana/src/relphot/src/extra.c
===================================================================
--- /trunk/Ohana/src/relphot/src/extra.c	(revision 37906)
+++ /trunk/Ohana/src/relphot/src/extra.c	(revision 37907)
@@ -30,4 +30,15 @@
 int isGPC1warp (int photcode) {
 
+  // diff warps get stack-like photcodes (kind of lame)
+  if (IS_DIFF_DB) {
+    if (photcode == 11000) return TRUE; // g-band
+    if (photcode == 11100) return TRUE; // r-band
+    if (photcode == 11200) return TRUE; // i-band
+    if (photcode == 11300) return TRUE; // z-band
+    if (photcode == 11400) return TRUE; // y-band
+    if (photcode == 11500) return TRUE; // w-band
+    return FALSE;
+  }
+
   if (photcode == 12000) return TRUE; // g-band
   if (photcode == 12100) return TRUE; // r-band
Index: /trunk/Ohana/src/relphot/src/reload_catalogs.c
===================================================================
--- /trunk/Ohana/src/relphot/src/reload_catalogs.c	(revision 37906)
+++ /trunk/Ohana/src/relphot/src/reload_catalogs.c	(revision 37907)
@@ -226,4 +226,5 @@
     if (RESET_ZEROPTS)    { snprintf (tmpline, 1024, "%s -reset-zpts",       	command); 		     			  strcpy (command, tmpline); }
     if (UPDATE)           { snprintf (tmpline, 1024, "%s -update",       	command); 		     			  strcpy (command, tmpline); }
+    if (IS_DIFF_DB)       { snprintf (tmpline, 1024, "%s -is-diff-db",       	command); 		     			  strcpy (command, tmpline); }
     if (!KEEP_UBERCAL)    { snprintf (tmpline, 1024, "%s -reset-ubercal",	command); 		                          strcpy (command, tmpline); }
     if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); 		          strcpy (command, tmpline); }
Index: /trunk/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- /trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 37906)
+++ /trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 37907)
@@ -62,5 +62,5 @@
 
     // only apply Stack operation on setMrelFinal in first pass 
-    if (isSetMrelFinal && (pass == 0)) {
+    if (isSetMrelFinal && (pass == 0) && !IS_DIFF_DB) {
       setMrelAverageStack (m, Nc, flatcorr, results, average, secfilt, &catalog[Nc].measure[m], catalog[Nc].Nmeasure);
       setGlobalObjStats (&catalog[Nc].average[j], &catalog[Nc].measure[m]);
@@ -703,4 +703,10 @@
   }
 
+  // for a diff db, we just want primary, if available or not
+  int priTessID, priProjID, priSkycellID;
+  if (IS_DIFF_DB) {
+    get_tess_ids(&priTessID, &priProjID, &priSkycellID, average[0].R, average[0].D);
+  }
+
   int Ns;
   for (Ns = 0; Ns < Nphotcodes; Ns++) {
@@ -718,6 +724,8 @@
     int stkTessID, stkProjID, stkSkycellID;
 
-    myAssert (secfilt[Nsec].stackBestOff <= Nmeasure, "stackBestOff out of range");
-    if (!FindImageSkycellID (secfilt[Nsec].stackBestOff, cat, &stkTessID, &stkProjID, &stkSkycellID)) continue;
+    if (!IS_DIFF_DB) {
+      myAssert (secfilt[Nsec].stackBestOff <= Nmeasure, "stackBestOff out of range");
+      if (!FindImageSkycellID (secfilt[Nsec].stackBestOff, cat, &stkTessID, &stkProjID, &stkSkycellID)) continue;
+    }
 
     off_t meas = measureOffset;
@@ -744,6 +752,10 @@
       measure[k].dbFlags &= ~ID_MEAS_WARP_USED;
 
-      if (!MatchImageSkycellID (meas, cat, stkTessID, stkProjID, stkSkycellID)) continue;
-
+      if (IS_DIFF_DB) {
+	if (!MatchImageSkycellID (meas, cat, priTessID, priProjID, priSkycellID)) continue;
+      } else {
+	if (!MatchImageSkycellID (meas, cat, stkTessID, stkProjID, stkSkycellID)) continue;
+      }
+ 
       if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad); 
 
@@ -811,5 +823,12 @@
       }
     }
-    if (Npsf < 1) continue;
+    if (Npsf < 1) {
+      secfilt[Nsec].Nwarp        = Nwarp;
+      secfilt[Nsec].NwarpGood    = NwarpGood;
+      secfilt[Nsec].NusedWrp     = Npsf;
+      secfilt[Nsec].NusedApWrp   = Nap;
+      secfilt[Nsec].NusedKronWrp = Nkron;
+      continue;
+    }
 
     found[Nsec] = TRUE;
