Index: /trunk/ippTools/scripts/dettest.sh
===================================================================
--- /trunk/ippTools/scripts/dettest.sh	(revision 14081)
+++ /trunk/ippTools/scripts/dettest.sh	(revision 14082)
@@ -62,5 +62,7 @@
 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 || exit 1
+dettool -adddetrunsummary -det_id $det_id -iteration 0 -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -accept -again || exit 1
+
+exit 1
 
 dettool -todetrunsummary || exit 1
Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 14081)
+++ /trunk/ippTools/src/dettool.c	(revision 14082)
@@ -5495,11 +5495,22 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // select detRun.det_id
-    // select detRun.iteration
-    // by:
-    // find the current iteration bassed on det_id
-    // find all exp_ids in the current det_id/iteration from detInputExp
-    // find all exp_ids in the current det_id/iteration from detResidExp
-    // compare the counts of exp_ids
+    // required
+    bool status = false;
+    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
+        return false;
+    }
+    if (!det_id) {
+        psError(PS_ERR_UNKNOWN, true, "-det_id is required");
+        return false;
+    }
+    
+    // optional
+    bool again = psMetadataLookupBool(&status, config->args, "-again");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -again");
+        return false;
+    }
 
     psString query = pxDataGet("dettool_find_completed_runs.sql");
@@ -5513,13 +5524,6 @@
         psMetadata *where = psMetadataAlloc();
         bool status = false;
-        psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
-            psFree(where);
-            psFree(query);
-            return false;
-        }
         if (det_id) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) {
+            if (!psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", (psS64)atoll(det_id))) {
                 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
                 psFree(where);
@@ -5603,4 +5607,23 @@
 
     psFree(output);
+
+    if (again) {
+        if (!startNewIteration(config, (psS64)atoll(det_id))) {
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "failed to start new iteration");
+            return false;
+        }
+    } else {
+        // set detRun.state to stop
+        if (!setDetRunState(config, (psS64)atoll(det_id), "stop")) {
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "failed to set detRun.state");
+            return false;
+        }
+    }
 
     if (!psDBCommit(config->dbh)) {
@@ -5831,5 +5854,5 @@
     // in an inconsistent UPDATE below.  I added this AND clause
     // though there may be a cleaner method (EAM 2006.10.08)
-    psStringAppend(&query, " WHERE detRun.det_id = %" PRId64 , det_id);
+    psStringAppend(&query, " WHERE det_id = %" PRId64 , det_id);
 
     if (!p_psDBRunQuery(config->dbh, query)) {
Index: /trunk/ippTools/src/dettoolConfig.c
===================================================================
--- /trunk/ippTools/src/dettoolConfig.c	(revision 14081)
+++ /trunk/ippTools/src/dettoolConfig.c	(revision 14082)
@@ -809,4 +809,6 @@
     psMetadataAddBool(adddetrunsummaryArgs, PS_LIST_TAIL, "-accept",  0,
             "declare that this detrun iteration is accepted as a master", false);
+    psMetadataAddBool(adddetrunsummaryArgs, PS_LIST_TAIL, "-again",  0,
+            "start a new iteration of this detrend run", false);
 
     // -detrunsummary
