Index: trunk/ippTools/src/stacktool.c
===================================================================
--- trunk/ippTools/src/stacktool.c	(revision 16688)
+++ trunk/ippTools/src/stacktool.c	(revision 16697)
@@ -103,4 +103,29 @@
     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
 
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_STR(config->args, where, "-select_exp_type", "exp_type", "==");
+    // map -inst -> camera
+    PXOPT_COPY_STR(config->args, where, "-select_inst", "camera", "==");
+    PXOPT_COPY_STR(config->args, where, "-select_telescope", "telescope", "==");
+    PXOPT_COPY_STR(config->args, where, "-select_filter", "filter", "==");
+    PXOPT_COPY_STR(config->args, where, "-select_uri", "uri", "==");
+    PXOPT_COPY_TIME(config->args, where, "-select_dateobs_begin", "dateobs", ">=");
+    PXOPT_COPY_TIME(config->args, where, "-select_dateobs_end", "dateobs", "<");
+    PXOPT_COPY_F32(config->args, where, "-select_airmass_min", "airmass", ">=");
+    PXOPT_COPY_F32(config->args, where, "-select_airmass_max", "airmass", "<=");
+    PXOPT_COPY_F32(config->args, where, "-select_sat_pixel_frac_max", "sat_pixel_frac", "<=");
+    PXOPT_COPY_F32(config->args, where, "-select_exp_time_min", "exp_time", ">=");
+    PXOPT_COPY_F32(config->args, where, "-select_exp_time_max", "exp_time", "<=");
+    PXOPT_COPY_F32(config->args, where, "-select_ccd_temp_min", "ccd_temp", ">=");
+    PXOPT_COPY_F32(config->args, where, "-select_ccd_temp_max", "ccd_temp", "<=");
+    PXOPT_COPY_F32(config->args, where, "-select_posang_min", "posang", ">=");
+    PXOPT_COPY_F32(config->args, where, "-select_posang_max", "posang", "<=");
+    PXOPT_COPY_F32(config->args, where, "-select_solang_min", "solang", ">=");
+    PXOPT_COPY_F32(config->args, where, "-select_solang_max", "solang", "<=");
+
+    if (!psListLength(where->list)) {
+        psFree(where);
+        where = NULL;
+    }
 
     psString query = pxDataGet("stacktool_find_complete_warps.sql");
@@ -110,6 +135,6 @@
     }
 
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL);
+    if (where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
