Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 7511)
+++ /trunk/ippTools/src/dettool.c	(revision 7512)
@@ -519,8 +519,19 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
     
-    // find all matching detProcessedImfiles
-    // where query should be pre-generated
+    // find all matching detProcessedImfiles where query should be
+    // pre-generated the entry for iteration must be pruned from the default
+    // search as processed imfiles aren't 'iterated'
+    bool status = false;
+    psMetadata *prunedWhere = psMetadataCopy(NULL, config->where);
+    psMetadataLookupS32(&status, prunedWhere, "iteration");
+    if (status) {
+        if (!psMetadataRemove(prunedWhere, 0, "iteration")) {
+            psError(PS_ERR_UNKNOWN, false, "failed to remove item iteration");
+            return false;
+        }
+    }
     psArray *processedImfiles = 
-        detProcessedImfileSelectRowObjects(config->dbh, config->where, 0);
+        detProcessedImfileSelectRowObjects(config->dbh, prunedWhere, 0);
+    psFree(prunedWhere);
     if (!processedImfiles) {
         psError(PS_ERR_UNKNOWN, false, "no detProcessedImfile rows found");
@@ -529,5 +540,4 @@
 
     // remove detStackedImfiles unless -unmask
-    bool status = false;
     if (!psMetadataLookupBool(&status, config->args, "-unmask")) {
         // detStackedImfiles doesn't have an exp_id so we have to generate the
@@ -540,4 +550,10 @@
             return false;
         }
+        psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "failed to lookup value for -iteration");
+            return false;
+        }
         psString class_id = psMetadataLookupStr(&status, config->args,
             "-class_id");
@@ -555,4 +571,11 @@
                 return false;
             }
+        }
+        // iteration always has a value (and it may be 0 anyways)
+        if (!psMetadataAddS32(where, PS_LIST_TAIL, "iteration", 0, "==",
+                    iteration)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
+            psFree(where);
+            return false;
         }
         if (class_id) {
Index: /trunk/ippTools/src/dettoolConfig.c
===================================================================
--- /trunk/ippTools/src/dettoolConfig.c	(revision 7511)
+++ /trunk/ippTools/src/dettoolConfig.c	(revision 7512)
@@ -70,4 +70,6 @@
     psMetadataAddStr(procArgs, PS_LIST_TAIL, "-det_id",  0,
         "search for detrend ID", NULL);
+    psMetadataAddS32(procArgs, PS_LIST_TAIL, "-iteration",  0,
+        "searchfor iteration number", 0);
     psMetadataAddStr(procArgs, PS_LIST_TAIL, "-exp_id",  0,
         "search for exp ID", NULL);
