Index: trunk/ippToPsps/jython/diffbatch.py
===================================================================
--- trunk/ippToPsps/jython/diffbatch.py	(revision 39165)
+++ trunk/ippToPsps/jython/diffbatch.py	(revision 39170)
@@ -336,5 +336,5 @@
         else:
             fluxScaleStr = "-1"
-            detIDoffset = self.posImageDetCount
+            detIDoffset = self.posImageDetCount[num]
 
         if isPosFile or self.haveNegFits[num]:
@@ -723,5 +723,5 @@
         self.haveSrcPos = {}
         self.haveNegFits = {}
-        self.posImageDetCount = 0
+        self.posImageDetCount = {}
 
         for num in self.number:
@@ -742,4 +742,5 @@
             ## if we have a negative image (inv.cmf), load that as well:
             self.haveNegFits[num] = 0
+            self.posImageDetCount[num] = 0
             if not self.negFits[num] == None:
                 fileNameNeg = self.negFits[num].getPath()
@@ -759,5 +760,6 @@
 
                 posTableName = "SkyChip_psf_" + str(num)
-                self.posImageDetCount = self.scratchDb.getRowCount(posTableName)
+                # self.posImageDetCount[num] = self.scratchDb.getMaxIPP_IDET(posTableName)
+                self.posImageDetCount[num] = self.scratchDb.getRowCount(posTableName)
 
             ## use stilts to get a list of the tables from the header
Index: trunk/ippToPsps/jython/scratchdb.py
===================================================================
--- trunk/ippToPsps/jython/scratchdb.py	(revision 39165)
+++ trunk/ippToPsps/jython/scratchdb.py	(revision 39170)
@@ -406,4 +406,18 @@
 
         return size
+
+    '''
+    Returns a row count for this table
+    '''
+    def getMaxIPP_IDET(self, table):
+
+        sql = "SELECT MAX(IPP_IDET) FROM " + table
+        rs = self.executeQuery(sql)  
+
+        if not rs.first():
+            self.logger.exception("Could not count rows for table: '" + table + "'")
+            return 0
+
+        return rs.getInt(1)
 
     '''
