Index: trunk/ippTools/src/camtool.c
===================================================================
--- trunk/ippTools/src/camtool.c	(revision 14147)
+++ trunk/ippTools/src/camtool.c	(revision 14227)
@@ -89,16 +89,15 @@
 }
 
-
-#define ADDPARAMSTR(from, to, name) \
+#define ADDRENAMEPARAMSTR(from, to, oldname, newname, comment) \
 { \
     bool status = false; \
-    psString str = psMetadataLookupStr(&status, from, "-" name); \
+    psString str = psMetadataLookupStr(&status, from, "-" oldname); \
     if (!status) { \
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" name); \
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" oldname); \
         return false; \
     } \
     if (str) { \
-        if (!psMetadataAddStr(to, PS_LIST_TAIL, name, 0, "==", str)) { \
-            psError(PS_ERR_UNKNOWN, false, "failed to add item " name); \
+        if (!psMetadataAddStr(to, PS_LIST_TAIL, newname, PS_META_DUPLICATE_OK, comment, str)) { \
+            psError(PS_ERR_UNKNOWN, false, "failed to add item " newname); \
             psFree(to); \
             return false; \
@@ -107,16 +106,18 @@
 }
 
-
-#define ADDPARAMF(from, to, type, name) \
+#define ADDPARAMSTR(from, to, name) \
+  ADDRENAMEPARAMSTR(from, to, name, name, "==")
+
+#define ADDRENAMEPARAMF(from, to, type, oldname, newname, comment) \
 { \
     bool status = false; \
-    ps##type var = psMetadataLookup##type(&status, from, "-" name); \
+    ps##type var = psMetadataLookup##type(&status, from, "-" oldname); \
     if (!status) { \
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" name); \
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" oldname); \
         return false; \
     } \
     if (!isnan(var)) { \
-        if (!psMetadataAdd##type(to, PS_LIST_TAIL, #name, 0, "==", var)) { \
-            psError(PS_ERR_UNKNOWN, false, "failed to add item " name); \
+        if (!psMetadataAdd##type(to, PS_LIST_TAIL, newname, PS_META_DUPLICATE_OK, comment, var)) { \
+            psError(PS_ERR_UNKNOWN, false, "failed to add item " newname); \
             psFree(to); \
             return false; \
@@ -125,4 +126,7 @@
 }
 
+#define ADDPARAMF(from, to, type, name) \
+  ADDRENAMEPARAMF(from, to, type, name, name, "==")
+
 static bool queueMode(pxConfig *config)
 {
@@ -130,4 +134,5 @@
 
     psMetadata *where = psMetadataAlloc();
+    // convert chip_id into a psS64
 {
     bool status = false;
@@ -145,26 +150,57 @@
     }
 }
-
-    ADDPARAMSTR(config->args, where, "exp_id");
+    // convert exp_id into a psS64
+{
+    bool status = false;
+    psString var = psMetadataLookupStr(&status, config->args, "-exp_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
+        return false;
+    }
+    if (var) {
+        if (!psMetadataAddS64(where, PS_LIST_TAIL, "exp_id", 0, "==", (psS64)atoll(var))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+            psFree(where);
+            return false; 
+        }
+    }
+}
     ADDPARAMSTR(config->args, where, "exp_name");
-    ADDPARAMSTR(config->args, where, "inst");
+    ADDRENAMEPARAMSTR(config->args, where, "inst", "camera", "==");
     ADDPARAMSTR(config->args, where, "telescope");
-    ADDPARAMSTR(config->args, where, "dateobs");
+    ADDPARAMSTR(config->args, where, "dateobs_begin");
+    ADDPARAMSTR(config->args, where, "dateobs_end");
+    ADDPARAMSTR(config->args, where, "exp_tag");
     ADDPARAMSTR(config->args, where, "exp_type");
-    ADDPARAMSTR(config->args, where, "imfiles");
-    ADDPARAMSTR(config->args, where, "workdir");
+    ADDPARAMSTR(config->args, where, "filelevel");
+    ADDPARAMSTR(config->args, where, "reduction");
     ADDPARAMSTR(config->args, where, "filter");
-    ADDPARAMF(config->args, where, F32, "airmass");
-    ADDPARAMF(config->args, where, F32, "ra");
-    ADDPARAMF(config->args, where, F32, "decl");
-    ADDPARAMF(config->args, where, F32, "exp_time");
-    ADDPARAMF(config->args, where, F64, "bg");
-    ADDPARAMF(config->args, where, F64, "bg_stdev");
-    ADDPARAMF(config->args, where, F64, "bg_mean_stdev");
-    ADDPARAMF(config->args, where, F64, "alt");
-    ADDPARAMF(config->args, where, F64, "az");
-    ADDPARAMF(config->args, where, F32, "ccd_temp");
-    ADDPARAMF(config->args, where, F64, "posang");
+    ADDRENAMEPARAMF(config->args, where, F64, "airmass_min", "airmass", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "airmass_max", "airmass", "<");
+    ADDRENAMEPARAMF(config->args, where, F64, "ra_min", "ra", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "ra_max", "ra", "<");
+    ADDRENAMEPARAMF(config->args, where, F64, "decl_min", "decl", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "decl_max", "decl", "<");
+    ADDRENAMEPARAMF(config->args, where, F32, "exp_time_min", "exp_time", ">=");
+    ADDRENAMEPARAMF(config->args, where, F32, "exp_time_max", "exp_time", "<");
+    ADDRENAMEPARAMF(config->args, where, F32, "sat_pixel_frac_min", "sat_pixel_frac", ">=");
+    ADDRENAMEPARAMF(config->args, where, F32, "sat_pixel_frac_max", "sat_pixel_frac", "<");
+    ADDRENAMEPARAMF(config->args, where, F64, "bg_min", "bt", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "bg_max", "bt", "<");
+    ADDRENAMEPARAMF(config->args, where, F64, "bg_stdev_min", "bg_stdev", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "bg_stdev_max", "bg_stdev", "<");
+    ADDRENAMEPARAMF(config->args, where, F64, "bg_mean_stdev_min", "bg_mean_stdev", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "bg_mean_stdev_max", "bg_mean_stdev", "<");
+    ADDRENAMEPARAMF(config->args, where, F64, "alt_min", "alt", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "alt_max", "alt", "<");
+    ADDRENAMEPARAMF(config->args, where, F64, "az_min", "az", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "az_max", "az", "<");
+    ADDRENAMEPARAMF(config->args, where, F32, "ccd_temp_min", "ccd_temp", ">=");
+    ADDRENAMEPARAMF(config->args, where, F32, "ccd_temp_max", "ccd_temp", "<");
+    ADDRENAMEPARAMF(config->args, where, F64, "posang_min", "posang", ">=");
+    ADDRENAMEPARAMF(config->args, where, F64, "posang_max", "posang", "<");
     ADDPARAMSTR(config->args, where, "object");
+    ADDRENAMEPARAMF(config->args, where, F32, "solang_min", "solang", ">=");
+    ADDRENAMEPARAMF(config->args, where, F32, "solang_max", "solang", "<");
 
     if (where->list->n < 1) {
@@ -204,6 +240,5 @@
     }
 
-    // find the chipProcessedExp exposures that we want to queue up.
-//    psString query = psStringCopy("SELECT * FROM chipRun WHERE chipRun.state = 'stop'");
+    // find the exp_id of all the exposures that we want to queue up.
     psString query = pxDataGet("camtool_find_chip_id.sql");
     if (!query) {
@@ -213,7 +248,7 @@
 
     if (where) {
-        psString whereClause = psDBGenerateWhereSQL(where, "");
+        psString whereClause = psDBGenerateWhereConditionSQL(where, "");
         psFree(where);
-        psStringAppend(&query, " %s", whereClause);
+        psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
     }
@@ -232,9 +267,11 @@
     }
     if (!psArrayLength(output)) {
-        psTrace("chiptool", PS_LOG_INFO, "no rows found");
+        psTrace("camtool", PS_LOG_INFO, "no rows found");
         psFree(output);
         return true;
     }
 
+    // start a transaction so we don't end up with an exp without any associted
+    // imfiles
     if (!psDBTransaction(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -248,5 +285,5 @@
     // old values in place (i.e., passing the values through).
 
-    // loop over our list of chipProcessedExp rows
+    // loop over our list of chipRun rows
     for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
