Index: trunk/ippTools/src/pztool.c
===================================================================
--- trunk/ippTools/src/pztool.c	(revision 18314)
+++ trunk/ippTools/src/pztool.c	(revision 18561)
@@ -162,13 +162,20 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    psMetadata *where = psMetadataAlloc();
+    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_STR(config->args, where,  "-exp_type",     "exp_type", "==");
+
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     psString query = psStringCopy("SELECT * FROM summitExp");
 
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "summitExp");
+    if (psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, "summitExp");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
     }
+    psFree(where);
 
     if (!p_psDBRunQuery(config->dbh, query)) {
@@ -206,8 +213,15 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    psMetadata *where = psMetadataAlloc();
+    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_STR(config->args, where,  "-exp_type",     "exp_type", "==");
+
     PXOPT_LOOKUP_BOOL(desc, config->args, "-desc", false);
     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
+    // XXX leave this query here ?
     psString query = psStringCopy(
             "SELECT"
@@ -223,9 +237,10 @@
         );
 
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadExp");
+    if (psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDownloadExp");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
     }
+    psFree(where);
 
     psStringAppend(&query, " ORDER BY summitExp.dateobs");
@@ -274,4 +289,10 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psMetadata *where = psMetadataAlloc();
+    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_STR(config->args, where,  "-exp_type",     "exp_type", "==");
 
     PXOPT_LOOKUP_BOOL(desc, config->args, "-desc", false);
@@ -300,6 +321,6 @@
         psStringAppend(&query, " WHERE camera = \"%s\"", camera);
 
-        if (config->where) {
-            psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadImfile");
+        if (psListLength(where->list)) {
+            psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDownloadImfile");
             psStringAppend(&query, " AND %s", whereClause);
             psFree(whereClause);
@@ -347,4 +368,5 @@
         psFree(result);
     }
+    psFree(where);
 
     // stitch the arrays of imfiles together
@@ -378,4 +400,6 @@
     // default values
     PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+
+    // NOTE : the rest of the command-line args are parsed in copydoneCompleteExp
 
     if (!pzDownloadImfileInsert(config->dbh,
@@ -447,4 +471,6 @@
     }
 
+    // XXX this is a bit ugly : could just use the PXOPT_COPY_* methods 
+    // and not pass exp_name, camera, or telescope as additional args
     psMetadata *where = psMetadataAlloc();
     if (exp_name) {
@@ -472,5 +498,5 @@
     }
 
-    if (config->where) {
+    if (psListLength(where->list)) {
         psString whereClause = psDBGenerateWhereSQL(where, NULL);
         psStringAppend(&query, " %s", whereClause);
@@ -720,10 +746,19 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
+    PXOPT_COPY_STR(config->args, where, "-inst", "inst", "==");
+    PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "==");
+    PXOPT_COPY_STR(config->args, where,  "-class", "class", "==");
+    PXOPT_COPY_STR(config->args, where,  "-class_id", "class_id", "==");
+
     PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
 
-    if (!pxSetFaultCode(config->dbh, "pzDownloadImfile", config->where, code)) {
+    if (!pxSetFaultCode(config->dbh, "pzDownloadImfile", where, code)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
-        return false;
-    }
+	psFree (where);
+	return false;
+    }
+    psFree(where);
 
     return true;
@@ -734,4 +769,11 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
+    PXOPT_COPY_STR(config->args, where, "-inst", "inst", "==");
+    PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "==");
+    PXOPT_COPY_STR(config->args, where,  "-class", "class", "==");
+    PXOPT_COPY_STR(config->args, where,  "-class_id", "class_id", "==");
 
     psString query = pxDataGet("pztool_revertcopied.sql");
@@ -741,9 +783,10 @@
     }
 
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadImfile");
+    if (psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDownloadImfile");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
     }
+    psFree(where);
 
     if (!p_psDBRunQuery(config->dbh, query)) {
@@ -803,4 +846,6 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // NOTE : the command-line args are parsed in copydoneCompleteExp
 
     // start a transaction so it's all rows or nothing
