Index: trunk/ippTools/src/camtool.c
===================================================================
--- trunk/ippTools/src/camtool.c	(revision 23589)
+++ 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")) {
Index: trunk/ippTools/src/camtoolConfig.c
===================================================================
--- trunk/ippTools/src/camtoolConfig.c	(revision 23589)
+++ trunk/ippTools/src/camtoolConfig.c	(revision 23590)
@@ -52,5 +52,6 @@
     psMetadata *definebyqueryArgs = psMetadataAlloc();
     pxcamSetSearchArgs(definebyqueryArgs);
-    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label", 0, "search for label", NULL);
+    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label",              0, "search by chipRun label", NULL);
+    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-reduction",          0, "search by chipRun reduction class", NULL);
 
     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_workdir",        0, "define workdir", NULL);
@@ -68,17 +69,19 @@
     // XXX need to allow multiple exp_ids
     psMetadata *updaterunArgs = psMetadataAlloc();
+    pxcamSetSearchArgs(updaterunArgs);
     psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-cam_id",             0, "search by cam_id", 0);
-    pxcamSetSearchArgs(updaterunArgs);
-    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0, "search for label", NULL);
-    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0, "search for state", NULL);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 		 0, "search by camRun label", NULL);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 		 0, "search by camRun state", NULL);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-reduction",          0, "search by camRun reduction class", NULL);
     psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-all",               0, "allow everything to be queued without search terms", false);
-    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state",              0, "set state", NULL);
-    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label",              0, "set label", NULL);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state",          0, "set state", NULL);
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label",          0, "set label", NULL);
 
     // -pendingexp
     psMetadata *pendingexpArgs = psMetadataAlloc();
-    psMetadataAddS64(pendingexpArgs, PS_LIST_TAIL, "-cam_id",            0, "search by camtool ID", 0);
     pxcamSetSearchArgs(pendingexpArgs);
-    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-label", 0, "search for label", NULL);
+    psMetadataAddS64(pendingexpArgs, PS_LIST_TAIL, "-cam_id",            0, "search by cam_id", 0);
+    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-label",             0, "search by camRun label", NULL);
+    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-reduction",         0, "search by camRun reduction class", NULL);
     psMetadataAddU64(pendingexpArgs, PS_LIST_TAIL, "-limit",             0, "limit result set to N items", 0);
     psMetadataAddBool(pendingexpArgs, PS_LIST_TAIL, "-simple",           0, "use the simple output format", false);
@@ -86,10 +89,12 @@
     // -pendingimfile
     psMetadata *pendingimfileArgs = psMetadataAlloc();
-    psMetadataAddS64(pendingimfileArgs, PS_LIST_TAIL, "-cam_id", 0,            "search by camtool ID", 0);
     pxcamSetSearchArgs(pendingimfileArgs);
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-label", 0, "search for label", NULL);
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-class", 0,            "search by class", NULL);
+    psMetadataAddS64(pendingimfileArgs, PS_LIST_TAIL, "-cam_id",   0,            "search by camtool ID", 0);
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-label",    0,            "search by camRun label", NULL);
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-reduction",0,            "search by camRun reduction class", NULL);
     psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-class_id", 0,            "search by class ID", NULL);
-    psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-simple", 0,            "use the simple output format", false);
+    psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
+
+    // XXX is this used? psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-class",    0,            "search by class", NULL);
 
     // -addprocessedexp
@@ -164,7 +169,8 @@
     // -processedexp
     psMetadata *processedexpArgs = psMetadataAlloc();
-    psMetadataAddS64(processedexpArgs, PS_LIST_TAIL, "-cam_id", 0,            "search by camtool ID", 0);
     pxcamSetSearchArgs(processedexpArgs);
-    psMetadataAddStr(processedexpArgs, PS_LIST_TAIL, "-label", 0, "search for label", NULL);
+    psMetadataAddS64(processedexpArgs, PS_LIST_TAIL, "-cam_id",   0,            "search by cam_id", 0);
+    psMetadataAddStr(processedexpArgs, PS_LIST_TAIL, "-label",    0,            "search by camRun label", NULL);
+    psMetadataAddStr(processedexpArgs, PS_LIST_TAIL, "-reduction",0,            "search by camRun reduction class", NULL);
 
     psMetadataAddU64(processedexpArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
@@ -177,10 +183,11 @@
     // XXX need to allow multiple exp_ids
     psMetadata *revertprocessedexpArgs = psMetadataAlloc();
-    psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-cam_id",  0,            "search by cam_id", 0);
     pxcamSetSearchArgs(revertprocessedexpArgs);
-    psMetadataAddStr(revertprocessedexpArgs, PS_LIST_TAIL, "-label", 0, "search for label", NULL);
+    psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-cam_id",   0,            "search by cam_id", 0);
+    psMetadataAddStr(revertprocessedexpArgs, PS_LIST_TAIL, "-label",    0,            "search by camRun label", NULL);
+    psMetadataAddStr(revertprocessedexpArgs, PS_LIST_TAIL, "-reduction",0,            "search by camRun reduction class", NULL);
+    psMetadataAddS16(revertprocessedexpArgs, PS_LIST_TAIL, "-code",     0,            "search by fault code", 0);
 
     psMetadataAddBool(revertprocessedexpArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
-    psMetadataAddS16(revertprocessedexpArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
 
     // -updateprocessedexp
Index: trunk/ippTools/src/pxcam.c
===================================================================
--- trunk/ippTools/src/pxcam.c	(revision 23589)
+++ trunk/ippTools/src/pxcam.c	(revision 23590)
@@ -42,5 +42,4 @@
     psMetadataAddStr(md,  PS_LIST_TAIL, "-comment",            0, "search by comment", NULL);
     psMetadataAddStr(md,  PS_LIST_TAIL, "-filelevel",          0, "search by filelevel", NULL);
-    psMetadataAddStr(md,  PS_LIST_TAIL, "-reduction",          0, "search by reduction class", NULL);
     psMetadataAddStr(md,  PS_LIST_TAIL, "-filter",             0, "search for filter", NULL);
     psMetadataAddF64(md,  PS_LIST_TAIL, "-airmass_min",        0, "define min airmass", NAN);
@@ -77,44 +76,43 @@
 bool pxcamGetSearchArgs (pxConfig *config, psMetadata *where) {
 
-    PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
-    PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "==");
-    PXOPT_COPY_STR(config->args, where, "-inst", "camera", "==");
-    PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "==");
-    PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "dateobs", ">=");
-    PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "dateobs", "<=");
-    PXOPT_COPY_STR(config->args, where, "-exp_tag", "exp_tag", "==");
-    PXOPT_COPY_STR(config->args, where, "-exp_type", "exp_type", "==");
-    PXOPT_COPY_STR(config->args, where, "-comment", "rawExp.comment", "LIKE");
-    PXOPT_COPY_STR(config->args, where, "-filelevel", "filelevel", "==");
-    PXOPT_COPY_STR(config->args, where, "-reduction", "reduction", "==");
-    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
-    PXOPT_COPY_F64(config->args, where, "-airmass_min", "airmass", ">=");
-    PXOPT_COPY_F64(config->args, where, "-airmass_max", "airmass", "<");
-    PXOPT_COPY_F64(config->args, where, "-ra_min", "ra", ">=");
-    PXOPT_COPY_F64(config->args, where, "-ra_max", "ra", "<");
-    PXOPT_COPY_F64(config->args, where, "-decl_min", "decl", ">=");
-    PXOPT_COPY_F64(config->args, where, "-decl_max", "decl", "<");
-    PXOPT_COPY_F32(config->args, where, "-exp_time_min", "exp_time", ">=");
-    PXOPT_COPY_F32(config->args, where, "-exp_time_max", "exp_time", "<");
-    PXOPT_COPY_F32(config->args, where, "-sat_pixel_frac_min", "sat_pixel_frac", ">=");
-    PXOPT_COPY_F32(config->args, where, "-sat_pixel_frac_max", "sat_pixel_frac", "<");
-    PXOPT_COPY_F64(config->args, where, "-bg_min", "bt", ">=");
-    PXOPT_COPY_F64(config->args, where, "-bg_max", "bt", "<");
-    PXOPT_COPY_F64(config->args, where, "-bg_stdev_min", "bg_stdev", ">=");
-    PXOPT_COPY_F64(config->args, where, "-bg_stdev_max", "bg_stdev", "<");
-    PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_min", "bg_mean_stdev", ">=");
-    PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_max", "bg_mean_stdev", "<");
-    PXOPT_COPY_F64(config->args, where, "-alt_min", "alt", ">=");
-    PXOPT_COPY_F64(config->args, where, "-alt_max", "alt", "<");
-    PXOPT_COPY_F64(config->args, where, "-az_min", "az", ">=");
-    PXOPT_COPY_F64(config->args, where, "-az_max", "az", "<");
-    PXOPT_COPY_F32(config->args, where, "-ccd_temp_min", "ccd_temp", ">=");
-    PXOPT_COPY_F32(config->args, where, "-ccd_temp_max", "ccd_temp", "<");
-    PXOPT_COPY_F64(config->args, where, "-posang_min", "posang", ">=");
-    PXOPT_COPY_F64(config->args, where, "-posang_max", "posang", "<");
-    PXOPT_COPY_STR(config->args, where, "-object", "object", "==");
-    PXOPT_COPY_F32(config->args, where, "-solang_min", "solang", ">=");
-    PXOPT_COPY_F32(config->args, where, "-solang_max", "solang", "<");
+    PXOPT_COPY_S64(config->args,  where, "-chip_id",            "chipRun.chip_id", 	 "==");
+    PXOPT_COPY_S64(config->args,  where, "-exp_id",             "rawExp.exp_id",   	 "==");
+    PXOPT_COPY_STR(config->args,  where, "-exp_name",           "rawExp.exp_name", 	 "==");
+    PXOPT_COPY_STR(config->args,  where, "-inst",               "rawExp.camera",   	 "==");
+    PXOPT_COPY_STR(config->args,  where, "-telescope",          "rawExp.telescope",	 "==");
+    PXOPT_COPY_TIME(config->args, where, "-dateobs_begin",      "rawExp.dateobs",  	 ">=");
+    PXOPT_COPY_TIME(config->args, where, "-dateobs_end",        "rawExp.dateobs",  	 "<=");
+    PXOPT_COPY_STR(config->args,  where, "-exp_tag",            "rawExp.exp_tag",  	 "==");
+    PXOPT_COPY_STR(config->args,  where, "-exp_type",           "rawExp.exp_type", 	 "==");
+    PXOPT_COPY_STR(config->args,  where, "-comment",            "rawExp.comment",  	 "LIKE");
+    PXOPT_COPY_STR(config->args,  where, "-filelevel",          "rawExp.filelevel",	 "==");
+    PXOPT_COPY_STR(config->args,  where, "-filter",             "rawExp.filter",         "==");
+    PXOPT_COPY_F64(config->args,  where, "-airmass_min",        "rawExp.airmass",        ">=");
+    PXOPT_COPY_F64(config->args,  where, "-airmass_max",        "rawExp.airmass",        "<");
+    PXOPT_COPY_F64(config->args,  where, "-ra_min",             "rawExp.ra",             ">=");
+    PXOPT_COPY_F64(config->args,  where, "-ra_max",             "rawExp.ra",             "<");
+    PXOPT_COPY_F64(config->args,  where, "-decl_min",           "rawExp.decl",           ">=");
+    PXOPT_COPY_F64(config->args,  where, "-decl_max",           "rawExp.decl",           "<");
+    PXOPT_COPY_F32(config->args,  where, "-exp_time_min",       "rawExp.exp_time",       ">=");
+    PXOPT_COPY_F32(config->args,  where, "-exp_time_max",       "rawExp.exp_time",       "<");
+    PXOPT_COPY_F32(config->args,  where, "-sat_pixel_frac_min", "rawExp.sat_pixel_frac", ">=");
+    PXOPT_COPY_F32(config->args,  where, "-sat_pixel_frac_max", "rawExp.sat_pixel_frac", "<");
+    PXOPT_COPY_F64(config->args,  where, "-bg_min",             "rawExp.bg",             ">=");
+    PXOPT_COPY_F64(config->args,  where, "-bg_max",             "rawExp.bg",             "<");
+    PXOPT_COPY_F64(config->args,  where, "-bg_stdev_min",       "rawExp.bg_stdev",       ">=");
+    PXOPT_COPY_F64(config->args,  where, "-bg_stdev_max",       "rawExp.bg_stdev",       "<");
+    PXOPT_COPY_F64(config->args,  where, "-bg_mean_stdev_min",  "rawExp.bg_mean_stdev",  ">=");
+    PXOPT_COPY_F64(config->args,  where, "-bg_mean_stdev_max",  "rawExp.bg_mean_stdev",  "<");
+    PXOPT_COPY_F64(config->args,  where, "-alt_min",            "rawExp.alt",            ">=");
+    PXOPT_COPY_F64(config->args,  where, "-alt_max",            "rawExp.alt",            "<");
+    PXOPT_COPY_F64(config->args,  where, "-az_min",             "rawExp.az",             ">=");
+    PXOPT_COPY_F64(config->args,  where, "-az_max",             "rawExp.az",             "<");
+    PXOPT_COPY_F32(config->args,  where, "-ccd_temp_min",       "rawExp.ccd_temp",       ">=");
+    PXOPT_COPY_F32(config->args,  where, "-ccd_temp_max",       "rawExp.ccd_temp",       "<");
+    PXOPT_COPY_F64(config->args,  where, "-posang_min",         "rawExp.posang",         ">=");
+    PXOPT_COPY_F64(config->args,  where, "-posang_max",         "rawExp.posang",         "<");
+    PXOPT_COPY_STR(config->args,  where, "-object",             "rawExp.object",         "==");
+    PXOPT_COPY_F32(config->args,  where, "-solang_min",         "rawExp.solang",         ">=");
+    PXOPT_COPY_F32(config->args,  where, "-solang_max",         "rawExp.solang",         "<");
 
     return true;
