Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 7600)
+++ trunk/ippTools/src/dettool.c	(revision 7602)
@@ -11,4 +11,5 @@
 static bool defineMode(pxConfig *config);
 static bool runsMode(pxConfig *config);
+static bool selectrunsMode(pxConfig *config);
 static bool inputMode(pxConfig *config);
 static bool rawMode(pxConfig *config);
@@ -50,4 +51,5 @@
         MODECASE(DETTOOL_MODE_DEFINE, defineMode);
         MODECASE(DETTOOL_MODE_RUNS, runsMode);
+        MODECASE(DETTOOL_MODE_SELECTRUNS, selectrunsMode);
         MODECASE(DETTOOL_MODE_INPUT, inputMode);
         MODECASE(DETTOOL_MODE_RAW, rawMode);
@@ -269,4 +271,61 @@
 
     psFree(runs);
+
+    return true;
+}
+
+static bool selectrunsMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, 0);
+
+    // -inst & -dete_type are required
+    bool status = false;
+    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
+        return false;
+    }
+    if (!camera) {
+        psError(PS_ERR_UNKNOWN, true, "-inst is required");
+        return false;
+    }
+    psString det_type = psMetadataLookupStr(&status, config->args, "-det_type");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_type");
+        return false;
+    }
+    if (!det_type) {
+        psError(PS_ERR_UNKNOWN, true, "-det_type is required");
+        return false;
+    }
+
+    char *query = "SELECT detRun.position, det_type, camera FROM detRun JOIN detInputExp where camera = '%s' and det_type = '%s' LIMIT 1";
+
+    if (!p_psDBRunQuery(config->dbh, query, camera, det_type)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    psArray *result = p_psDBFetchResult(config->dbh);
+    if (!result) {
+    }
+
+    // sanity check the result
+    if (psArrayLength(result) != 1) {
+    }
+
+    // just a view... doesn't need to be free'd
+    psMetadata *run = result->data[0];
+
+    psS32 det_id = psMetadataLookupS32(&status, run, "position");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for position");
+        psFree(result);
+        return false;
+    }
+
+    psFree(result);
+
+    fprintf(stdout, "FLAT CHIP %d DONE\n", det_id);
 
     return true;
@@ -1987,2 +2046,3 @@
     return newIteration;
 }
+
