Index: /trunk/ippTools/configure.ac
===================================================================
--- /trunk/ippTools/configure.ac	(revision 9077)
+++ /trunk/ippTools/configure.ac	(revision 9078)
@@ -16,5 +16,5 @@
 PKG_CHECK_MODULES([PSLIB], [pslib >= 0.12.99]) 
 PKG_CHECK_MODULES([PSMODULES], [psmodules >= 0.12.0]) 
-PKG_CHECK_MODULES([IPPDB], [ippdb >= 0.0.38]) 
+PKG_CHECK_MODULES([IPPDB], [ippdb >= 0.0.39]) 
 
 AC_PROG_PERL_MODULES(
Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 9077)
+++ /trunk/ippTools/src/dettool.c	(revision 9078)
@@ -1050,4 +1050,95 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
+  
+    // select detProcessedImfile.det_id
+    // select detRun.iteration
+    // select detRun.det_type
+    // select detProcessedImfile.exp_tag
+    // by:
+    // find the current iteration bassed on det_id
+    // find all exp_tags in the current det_id/iteration from detInputExp
+    // find all rawImfiles in the current exp_tags
+    // compare to detProcessedImfiles by det_id/exp_tag
+    // found how many imfile there are in each class_id
+    // and:
+    // det_id is not in detProcessedExp;
+    // iteration is not in detProcessedExp;
+    // class_id is not in detProcessedExp;
+
+    psString query = psStringCopy(
+        " SELECT"
+        "    detProcessedImfile.det_id,"
+        "    detRun.iteration,"
+        "    detRun.det_type,"
+        "    detProcessedImfile.exp_tag"
+        " FROM detRun"
+        " JOIN detInputExp"
+        "    ON detRun.position = detInputExp.det_id"
+        "    AND detRun.iteration = detInputExp.iteration"
+        " JOIN rawDetrendExp"
+        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN detProcessedImfile"
+        "    ON detInputExp.det_id = detProcessedImfile.det_id"
+        "    AND detInputExp.exp_tag = detProcessedImfile.exp_tag"
+        " LEFT JOIN detProcessedExp"
+        "    ON detInputExp.det_id = detStackedImfile.det_id"
+        "    AND detInputExp.iteration = detStackedImfile.iteration"
+        "    AND detProcessedImfile.exp_tag= detStackedImfile.exp_tag"
+        " LEFT JOIN rawImfile"
+        "    ON detInputExp.exp_tag = rawImfile.exp_tag"
+        "    AND detProcessedImfile.class_id = rawImfile.class_id"
+        " WHERE"
+        "    detProcessedExp.det_id IS NULL"
+        "    AND detProcessedExp.iteration IS NULL"
+        "    AND detProcessedExp.exp_tag IS NULL"
+        "    AND detInputExp.include = 1"
+        " GROUP BY"
+        "    detProcessedImfile.class_id,"
+        "    rawImfile.class_id"
+        " HAVING"
+        "    COUNT(detProcessedImfile.class_id) = COUNT(rawImfile.class_id)"
+        );
+
+    // XXX does it make sens to accept any search params?
+#if 0
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where);
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+#endif
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    psArray *output = p_psDBFetchResult(config->dbh);
+    if (!output) {
+        // XXX check psError here
+        psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found");
+        return false;
+    }
+
+    bool simple = false;
+    {
+        bool status = false;
+        simple = psMetadataLookupBool(&status, config->args, "-simple");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
+            return false;
+        }
+    }
+
+    // negative simple so the default is true
+    if (!ippdbPrintMetadatas(stdout, output, "detProcessedImfile", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
 
     return true;
Index: /trunk/ippTools/src/dettoolConfig.c
===================================================================
--- /trunk/ippTools/src/dettoolConfig.c	(revision 9077)
+++ /trunk/ippTools/src/dettoolConfig.c	(revision 9078)
@@ -167,4 +167,6 @@
     psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-exp_tag",  0,
         "define detrend ID (required)", NULL);
+    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-recip",  0,
+        "define recipe (required)", NULL);
     psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-bg",  0,
         "define exposue background", NAN);
Index: /trunk/ippTools/src/pxtables.c
===================================================================
--- /trunk/ippTools/src/pxtables.c	(revision 9077)
+++ /trunk/ippTools/src/pxtables.c	(revision 9078)
@@ -42,4 +42,5 @@
     CREATE_TABLE(detInputExpCreateTable);
     CREATE_TABLE(detProcessedImfileCreateTable);
+    CREATE_TABLE(detProcessedExpCreateTable);
     CREATE_TABLE(detStackedImfileCreateTable);
     CREATE_TABLE(detNormalizedStatImfileCreateTable);
@@ -97,4 +98,5 @@
     DROP_TABLE(detInputExpDropTable);
     DROP_TABLE(detProcessedImfileDropTable);
+    DROP_TABLE(detProcessedExpDropTable);
     DROP_TABLE(detStackedImfileDropTable);
     DROP_TABLE(detNormalizedStatImfileDropTable);
