Index: trunk/ippTools/src/camtool.c
===================================================================
--- trunk/ippTools/src/camtool.c	(revision 23310)
+++ trunk/ippTools/src/camtool.c	(revision 23590)
@@ -109,5 +109,6 @@
     psMetadata *where = psMetadataAlloc();
     pxcamGetSearchArgs (config, where);
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    PXOPT_COPY_STR(config->args, where, "-label",     "chipRun.label",     "==");
+    PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
 
     if (!psListLength(where->list)
@@ -223,8 +224,9 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-cam_id", "cam_id", "==");
     pxcamGetSearchArgs (config, where);
-    PXOPT_COPY_STR(config->args, where, "-label", "camRun.label", "==");
-    PXOPT_COPY_STR(config->args, where, "-state", "camRun.state", "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-label",     "camRun.label", "==");
+    PXOPT_COPY_STR(config->args, where, "-state",     "camRun.state", "==");
+    PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "==");
 
     if (!psListLength(where->list)
@@ -271,7 +273,8 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-cam_id", "cam_id", "==");
     pxcamGetSearchArgs (config, where);
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-label",     "camRun.label", "==");
+    PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "==");
 
     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
@@ -334,10 +337,12 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-cam_id",   "cam_id",   "==");
-    PXOPT_COPY_S64(config->args, where, "-chip_id",  "chip_id",  "==");
-    PXOPT_COPY_STR(config->args, where, "-class",    "class",    "==");
-    PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
     pxcamGetSearchArgs (config, where);
-    PXOPT_COPY_STR(config->args, where, "-label", "camRun.label", "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",                "==");
+    PXOPT_COPY_STR(config->args, where, "-label",     "camRun.label",                 "==");
+    PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction",             "==");
+    PXOPT_COPY_S64(config->args, where, "-chip_id",   "chipRun.chip_id",              "==");
+    PXOPT_COPY_STR(config->args, where, "-class_id",  "chipProcessedImfile.class_id", "==");
+
+    // XXX is this used? PXOPT_COPY_STR(config->args, where, "-class",    "class",         "==");
 
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
@@ -649,7 +654,8 @@
     // generate restrictions
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-cam_id",   "cam_id",   "==");
     pxcamGetSearchArgs (config, where);
-    PXOPT_COPY_STR(config->args, where, "-label", "camRun.label", "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",    "==");
+    PXOPT_COPY_STR(config->args, where, "-label",     "camRun.label",     "==");
+    PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "==");
 
     psString query = pxDataGet("camtool_find_processedexp.sql");
@@ -674,4 +680,7 @@
     }
 
+    // order by cam_id so that the postage stamp parser can easliy find the 'latest' astrometry
+    psStringAppend(&query, " ORDER BY cam_id");
+
     // treat limit == 0 as "no limit"
     if (limit) {
@@ -681,7 +690,4 @@
     }
 
-    // order by cam_id so that the postage stamp parser can easliy find the 'latest' astrometry
-    psStringAppend(&query, "\nORDER BY cam_id");
-
     if (!p_psDBRunQuery(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -720,8 +726,9 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "==");
     pxcamGetSearchArgs (config, where);
-    PXOPT_COPY_STR(config->args, where, "-label", "camRun.label", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "camProcessedExp.fault", "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",         "==");
+    PXOPT_COPY_STR(config->args, where, "-label",     "camRun.label",          "==");
+    PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction",      "==");
+    PXOPT_COPY_S16(config->args, where, "-code",      "camProcessedExp.fault", "==");
 
     if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
