Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 7200)
+++ trunk/ippTools/src/dettool.c	(revision 7205)
@@ -15,4 +15,5 @@
 static bool stacMode(pxConfig *config);
 static psArray *validDetInputClassIds(pxConfig *config, const char *det_id);
+static psArray *searchInputImfiles(pxConfig *config, const char *det_id);
 static bool stacframeMode(pxConfig *config);
 static bool addnormalizedMode(pxConfig *config);
@@ -420,4 +421,18 @@
         }
         psFree(stackedImfiles);
+    }
+
+    // if -chip is specified only return results for complete 'chip' sets.
+    // I.e., when all of the same class_id for the input exposures have been
+    // processed.  This should be done after detStackedImfiles are masked so we
+    // don't have to doen this check unless we have to.
+    if (psMetadataLookupBool(&status, config->args, "-chip")) {
+        psArray *rawImfiles = searchInputImfiles(config, det_id);
+
+
+
+
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
+        return false;
     }
 
@@ -672,38 +687,7 @@
     PS_ASSERT_PTR_NON_NULL(det_id, NULL);
 
-    psArray *inputExps = NULL;
-    {
-        psMetadata *where = psMetadataAlloc();
-        if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==",
-                (psS32)atoi(det_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
-            psFree(where);
-            return NULL;
-        }
-        inputExps = detInputExpSelectRowObjects(config->dbh, where, 0);
-        psFree(where);
-    }
-    if (!inputExps) {
-        psError(PS_ERR_UNKNOWN, false, "no detInputExp rows found");
-    }
-
-    // find rawImfiles associated with detInputExps
-    psArray *rawImfiles = NULL;
-    {
-        psMetadata *where = psMetadataAlloc();
-        for (long i = 0; i < psArrayLength(inputExps); i++) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==",
-                    ((detInputExpRow *)inputExps->data[i])->exp_id)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
-                psFree(where);
-                return NULL;
-            }
-        }
-        rawImfiles = rawImfileSelectRowObjects(config->dbh, where, 0);
-        // XXX this really should be sorted for uniqueness
-        psFree(where);
-    }
+    psArray *rawImfiles = searchInputImfiles(config, det_id);
     if (!rawImfiles) {
-        psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found");
+        return NULL;
     }
 
@@ -732,4 +716,52 @@
 }
 
+static psArray *searchInputImfiles(pxConfig *config, const char *det_id)
+{
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    // det_id is input as a string because the fact that it is an integer
+    // is just a database impliementation detail.
+    PS_ASSERT_PTR_NON_NULL(det_id, NULL);
+
+    psArray *inputExps = NULL;
+    {
+        psMetadata *where = psMetadataAlloc();
+        if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==",
+                (psS32)atoi(det_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
+            psFree(where);
+            return NULL;
+        }
+        inputExps = detInputExpSelectRowObjects(config->dbh, where, 0);
+        psFree(where);
+    }
+    if (!inputExps) {
+        psError(PS_ERR_UNKNOWN, false, "no detInputExp rows found");
+        return NULL;
+    }
+
+    // find rawImfiles associated with detInputExps
+    psArray *rawImfiles = NULL;
+    {
+        psMetadata *where = psMetadataAlloc();
+        for (long i = 0; i < psArrayLength(inputExps); i++) {
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==",
+                    ((detInputExpRow *)inputExps->data[i])->exp_id)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+                psFree(where);
+                return NULL;
+            }
+        }
+        rawImfiles = rawImfileSelectRowObjects(config->dbh, where, 0);
+        // XXX this really should be sorted for uniqueness
+        psFree(where);
+    }
+    if (!rawImfiles) {
+        psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found");
+        return NULL;
+    }
+
+    return rawImfiles;
+}
+
 static bool addnormalizedMode(pxConfig *config)
 {
