Index: /trunk/ippTools/scripts/dettest.sh
===================================================================
--- /trunk/ippTools/scripts/dettest.sh	(revision 15827)
+++ /trunk/ippTools/scripts/dettest.sh	(revision 15828)
@@ -62,5 +62,5 @@
 dettool -updateresidexp -det_id $det_id -iteration 0 -exp_id 2 || exit 1
 
-dettool -adddetrunsummary -det_id $det_id -iteration 0 -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -accept -again || exit 1
+dettool -adddetrunsummary -det_id $det_id -iteration 0 -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -accept || exit 1
 
 dettool -todetrunsummary || exit 1
Index: /trunk/ippTools/share/Makefile.am
===================================================================
--- /trunk/ippTools/share/Makefile.am	(revision 15827)
+++ /trunk/ippTools/share/Makefile.am	(revision 15828)
@@ -13,5 +13,6 @@
 	detselect_search.sql \
 	detselect_select.sql \
-	dettool_correct_pendingimfiles.sql \
+	dettool_tocorrectimfile.sql \
+	dettool_tocorrectexp.sql \
 	dettool_find_completed_runs.sql \
 	dettool_normalizedstat.sql \
Index: unk/ippTools/share/dettool_correct_pendingimfiles.sql
===================================================================
--- /trunk/ippTools/share/dettool_correct_pendingimfiles.sql	(revision 15827)
+++ 	(revision )
@@ -1,31 +1,0 @@
-SELECT
-    det1.*,
-    imfile.class_id,
-    imfile.uri,
-    imfile.bg,
-    imfile.bg_stdev,
-    imfile.bg_mean_stdev,
-    imfile.user_1,
-    imfile.user_2,
-    imfile.user_3,
-    imfile.user_4,
-    imfile.user_5,
-    imfile.path_base,
-    imfile.fault
-FROM detRun AS det1
-INNER JOIN detRun as det2
-    ON det1.parent = det2.det_id 
-JOIN detNormalizedImfile as imfile
-    ON det2.det_id = imfile.det_id
-    AND det2.iteration = imfile.iteration
-LEFT JOIN detRegisteredImfile
-    ON det1.det_id = detRegisteredImfile.det_id
-    AND det1.iteration = detRegisteredImfile.iteration
-    AND imfile.class_id = detRegisteredImfile.class_id
-WHERE 
-    det1.state = 'run'
-    AND det1.mode = 'correction'
-    AND det2.state = 'stop'
-    AND detRegisteredImfile.det_id IS NULL
-    AND detRegisteredImfile.iteration IS NULL
-    AND detRegisteredImfile.class_id IS NULL
Index: /trunk/ippTools/share/dettool_tocorrectexp.sql
===================================================================
--- /trunk/ippTools/share/dettool_tocorrectexp.sql	(revision 15828)
+++ /trunk/ippTools/share/dettool_tocorrectexp.sql	(revision 15828)
@@ -0,0 +1,4 @@
+SELECT * FROM detRun
+WHERE
+    detRun.mode = 'correction'
+    AND detRun.state = 'run'
Index: /trunk/ippTools/share/dettool_tocorrectimfile.sql
===================================================================
--- /trunk/ippTools/share/dettool_tocorrectimfile.sql	(revision 15828)
+++ /trunk/ippTools/share/dettool_tocorrectimfile.sql	(revision 15828)
@@ -0,0 +1,31 @@
+SELECT
+    det1.*,
+    imfile.class_id,
+    imfile.uri,
+    imfile.bg,
+    imfile.bg_stdev,
+    imfile.bg_mean_stdev,
+    imfile.user_1,
+    imfile.user_2,
+    imfile.user_3,
+    imfile.user_4,
+    imfile.user_5,
+    imfile.path_base,
+    imfile.fault
+FROM detRun AS det1
+INNER JOIN detRun as det2
+    ON det1.parent = det2.det_id 
+JOIN detNormalizedImfile as imfile
+    ON det2.det_id = imfile.det_id
+    AND det2.iteration = imfile.iteration
+LEFT JOIN detRegisteredImfile
+    ON det1.det_id = detRegisteredImfile.det_id
+    AND det1.iteration = detRegisteredImfile.iteration
+    AND imfile.class_id = detRegisteredImfile.class_id
+WHERE 
+    det1.state = 'run'
+    AND det1.mode = 'correction'
+    AND det2.state = 'stop'
+    AND detRegisteredImfile.det_id IS NULL
+    AND detRegisteredImfile.iteration IS NULL
+    AND detRegisteredImfile.class_id IS NULL
Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 15827)
+++ /trunk/ippTools/src/dettool.c	(revision 15828)
@@ -128,9 +128,11 @@
         MODECASE(DETTOOL_MODE_DEFINEBYQUERY,    definebyqueryMode);
         MODECASE(DETTOOL_MODE_DEFINEBYDETRUN,   definebydetrunMode);
-        MODECASE(DETTOOL_MODE_MAKECORRECTION,   makecorrectionMode);
         MODECASE(DETTOOL_MODE_RUNS,             runsMode);
         MODECASE(DETTOOL_MODE_CHILDLESSRUN,     childlessrunMode);
         MODECASE(DETTOOL_MODE_INPUT,            inputMode);
         MODECASE(DETTOOL_MODE_RAW,              rawMode);
+        // correction
+        MODECASE(DETTOOL_MODE_TOCORRECTEXP,      tocorrectexpMode);
+        MODECASE(DETTOOL_MODE_TOCORRECTIMFILE,   tocorrectimfileMode);
         // imfile
         MODECASE(DETTOOL_MODE_TOPROCESSEDIMFILE,toprocessedimfileMode);
Index: /trunk/ippTools/src/dettool.h
===================================================================
--- /trunk/ippTools/src/dettool.h	(revision 15827)
+++ /trunk/ippTools/src/dettool.h	(revision 15828)
@@ -30,4 +30,6 @@
     DETTOOL_MODE_DEFINEBYDETRUN,
     DETTOOL_MODE_MAKECORRECTION,
+    DETTOOL_MODE_TOCORRECTEXP,
+    DETTOOL_MODE_TOCORRECTIMFILE,
     DETTOOL_MODE_RUNS,
     DETTOOL_MODE_CHILDLESSRUN,
@@ -80,4 +82,6 @@
 
 bool makecorrectionMode(pxConfig *config);
+bool tocorrectexpMode(pxConfig *config);
+bool tocorrectimfileMode(pxConfig *config);
 
 #endif // DETTOOL_H
Index: /trunk/ippTools/src/dettoolConfig.c
===================================================================
--- /trunk/ippTools/src/dettoolConfig.c	(revision 15827)
+++ /trunk/ippTools/src/dettoolConfig.c	(revision 15828)
@@ -274,4 +274,22 @@
     psMetadataAddStr(makecorrectionArgs, PS_LIST_TAIL, "-det_id",  0,
             "det ID to be corrected (required)", NULL);
+    psMetadataAddBool(makecorrectionArgs, PS_LIST_TAIL, "-simple", 0,
+            "use the simple output format", false);
+
+    // -tocorrectexp
+    psMetadata *tocorrectexpArgs = psMetadataAlloc();
+    psMetadataAddU64(tocorrectexpArgs, PS_LIST_TAIL, "-limit",  0,
+            "limit result set to N items", 0);
+    psMetadataAddBool(tocorrectexpArgs, PS_LIST_TAIL, "-simple",  0,
+            "use the simple output format", false);
+
+    // -tocorrectimfile
+    psMetadata *tocorrectimfileArgs = psMetadataAlloc();
+    psMetadataAddStr(tocorrectimfileArgs, PS_LIST_TAIL, "-det_id", 0,
+            "search for detrend ID", NULL);
+    psMetadataAddU64(tocorrectimfileArgs, PS_LIST_TAIL, "-limit",  0,
+            "limit result set to N items", 0);
+    psMetadataAddBool(tocorrectimfileArgs, PS_LIST_TAIL, "-simple",  0,
+            "use the simple output format", false);
 
     // -runs
@@ -1070,4 +1088,6 @@
     PXTOOL_ADD_MODE("-definebydetrun",  "", DETTOOL_MODE_DEFINEBYDETRUN, definebydetrunArgs);
     PXTOOL_ADD_MODE("-makecorrection",  "", DETTOOL_MODE_MAKECORRECTION, makecorrectionArgs);
+    PXTOOL_ADD_MODE("-tocorrectexp",    "", DETTOOL_MODE_TOCORRECTEXP, tocorrectexpArgs);
+    PXTOOL_ADD_MODE("-tocorrectimfile", "", DETTOOL_MODE_TOCORRECTIMFILE, tocorrectimfileArgs);
     PXTOOL_ADD_MODE("-raw",             "", DETTOOL_MODE_RAW,           rawArgs);
     PXTOOL_ADD_MODE("-runs",            "", DETTOOL_MODE_RUNS,          runsArgs);
Index: /trunk/ippTools/src/dettool_correction.c
===================================================================
--- /trunk/ippTools/src/dettool_correction.c	(revision 15827)
+++ /trunk/ippTools/src/dettool_correction.c	(revision 15828)
@@ -95,8 +95,32 @@
     psFree(runs);
 
-
-    // point of no return for det_id creation
+    // print the new detRun
+    psS64 new_det_id = psDBLastInsertID(config->dbh);
+
     if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    psArray *detRuns = NULL;
+    {
+        psMetadata *where = psMetadataAlloc();
+        psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", new_det_id);
+        detRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
+        psFree(where);
+    }
+    if (!detRuns) {
+        psError(PS_ERR_UNKNOWN, false, "can't find the detRun we just created");
+        return false;
+    }
+    // sanity check results
+    if (psArrayLength(detRuns) != 1) {
+        psAbort("found more then one detRun matching det_id %" PRId64 "(this should not happen)", new_det_id);
+        return false;
+    }
+
+    if (!convertIdToStr(detRuns)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
+        psFree(detRuns);
         return false;
     }
@@ -112,29 +136,4 @@
     }
 
-#if 0
-    // print the new det_id
-    psArray *detRuns = NULL;
-    {
-        psMetadata *where = psMetadataAlloc();
-        psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", det_id);
-        detRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
-        psFree(where);
-    }
-    if (!detRuns) {
-        psError(PS_ERR_UNKNOWN, false, "can't find the detRun we just created");
-        return false;
-    }
-    // sanity check results
-    if (psArrayLength(detRuns) != 1) {
-        psAbort("found more then one detRun matching det_id %" PRId64 " (this should not happen)", det_id);
-        return false;
-    }
-
-    if (!convertIdToStr(detRuns)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(detRuns);
-        return false;
-    }
-
     // negative simple so the default is true
     if (!ippdbPrintMetadatas(stdout, detRuns, "detRun", !simple)) {
@@ -144,6 +143,139 @@
     }
     psFree(detRuns);
-#endif
 
     return true;
 }
+
+bool tocorrectexpMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        return false;
+    }
+
+    psString query = pxDataGet("dettool_tocorrectexp.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
+
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
+    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) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        psTrace("dettool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    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, "detRun", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
+    return true;
+}
+
+bool tocorrectimfileMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        return false;
+    }
+
+    psString query = pxDataGet("dettool_tocorrectimfile.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "det1");
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
+    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) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        psTrace("dettool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    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, "detPendingCorrectImfile", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
+    return true;
+}
