Index: trunk/ippTools/src/chiptool.c
===================================================================
--- trunk/ippTools/src/chiptool.c	(revision 19132)
+++ trunk/ippTools/src/chiptool.c	(revision 19324)
@@ -30,4 +30,5 @@
 #include "pxtools.h"
 #include "pxdata.h"
+#include "pxchip.h"
 
 #include "chiptool.h"
@@ -113,45 +114,7 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-exp_id", "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, "-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", "bg", ">=");
-    PXOPT_COPY_F64(config->args, where, "-bg_max", "bg", "<");
-    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_STR(config->args, where, "-comment", "comment", "LIKE");
-
-    if (!psListLength(where->list)
-        && !psMetadataLookupBool(NULL, config->args, "-all")) {
+    pxchipGetSearchArgs (config, where);
+
+    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
         psFree(where);
         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
@@ -170,4 +133,5 @@
     PXOPT_COPY_STR(config->args, where, "-exp_type", "exp_type", "==");
     PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     // find the exp_id of all the exposures that we want to queue up.
@@ -184,13 +148,5 @@
         psFree(whereClause);
     }
-
     psFree(where);
-
-    if (pretend) {
-        // then stop before running the query
-        fprintf(stderr, "%s\n", query);
-        psFree(query);
-        return true;
-    }
 
     if (!p_psDBRunQuery(config->dbh, query)) {
@@ -208,4 +164,15 @@
     if (!psArrayLength(output)) {
         psTrace("chiptool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    if (pretend) {
+        // negative simple so the default is true
+        if (!rawExpPrintObjects(stdout, output, !simple)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to print array");
+            psFree(output);
+            return false;
+        }
         psFree(output);
         return true;
@@ -260,43 +227,5 @@
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args,  where, "-chip_id", "chip_id", "==");
-    PXOPT_COPY_S64(config->args,  where, "-exp_id", "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, "-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", "bg", ">=");
-    PXOPT_COPY_F64(config->args,  where, "-bg_max", "bg", "<");
-    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_STR(config->args,  where, "-label", "label", "==");
+    pxchipGetSearchArgs (config, where);
 
     if (!psListLength(where->list)
@@ -348,8 +277,5 @@
     psMetadata *where = psMetadataAlloc();
     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, "-class_id", "rawImfile.class_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-inst", "rawExp.telescope", "==");
-    PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "==");
+    pxchipGetSearchArgs (config, where);
 
     psString query = pxDataGet("chiptool_pendingimfile.sql");
@@ -522,9 +448,6 @@
     psMetadata *where = psMetadataAlloc();
     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, "-class_id", "chipProcessedImfile.class_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-inst", "rawExp.camera", "==");
-    PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "==");
+    pxchipGetSearchArgs (config, where);
 
     psString query = pxDataGet("chiptool_processedimfile.sql");
@@ -591,51 +514,10 @@
 
     psMetadata *where = psMetadataAlloc();
+    pxchipGetSearchArgs (config, where);
 
     // from chipRun (XXX is missing from sql)
     PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
     PXOPT_COPY_STR(config->args, where, "-label",     "chipRun.label", "==");
-
-    // from chipProcessedImfile
-    PXOPT_COPY_S64(config->args, where, "-chip_id", "chipProcessedImfile.chip_id", "==");
-    PXOPT_COPY_S64(config->args, where, "-exp_id", "chipProcessedImfile.exp_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-class_id", "chipProcessedImfile.class_id", "==");
-    PXOPT_COPY_F64(config->args, where, "-bg_min", "chipProcessedImfile.bt", ">=");
-    PXOPT_COPY_F64(config->args, where, "-bg_max", "chipProcessedImfile.bt", "<");
-    PXOPT_COPY_F64(config->args, where, "-bg_stdev_min", "chipProcessedImfile.bg_stdev", ">=");
-    PXOPT_COPY_F64(config->args, where, "-bg_stdev_max", "chipProcessedImfile.bg_stdev", "<");
-    PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_min", "chipProcessedImfile.bg_mean_stdev", ">=");
-    PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_max", "chipProcessedImfile.bg_mean_stdev", "<");
     PXOPT_COPY_S16(config->args, where, "-code", "chipProcessedImfile.fault", "=");
-
-    // from rawExp
-    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, "-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, "-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", "<");
 
     if (!psListLength(where->list)
@@ -677,7 +559,5 @@
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
-    PXOPT_COPY_S64(config->args, where, "-exp_id",  "exp_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
-
+    pxchipGetSearchArgs (config, where);
     PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
 
