Index: /trunk/ippTools/configure.ac
===================================================================
--- /trunk/ippTools/configure.ac	(revision 6658)
+++ /trunk/ippTools/configure.ac	(revision 6659)
@@ -18,5 +18,6 @@
 PKG_CHECK_MODULES([METADATADB], [metadatadb >= 0.0.1]) 
 
-pxtools_CFLAGS="-Wall -Werror -std=c99"
+dnl pxtools_CFLAGS="-Wall -Werror -std=c99"
+pxtools_CFLAGS="-Wall -std=c99"
 AC_SUBST([pxtools_CFLAGS])
 
Index: /trunk/ippTools/src/Makefile.am
===================================================================
--- /trunk/ippTools/src/Makefile.am	(revision 6658)
+++ /trunk/ippTools/src/Makefile.am	(revision 6659)
@@ -1,3 +1,3 @@
-bin_PROGRAMS = pxadmin p2search p0search
+bin_PROGRAMS = pxadmin pzsearch p2search p0search
 
 include_HEADERS = pxtools.h
@@ -19,4 +19,10 @@
 # for pxtools.h
 AM_CPPFLAGS = -I$(top_srcdir)/src$
+
+pzsearch_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(METADATADB_CFLAGS) $(pxtools_CFLAGS)
+pzsearch_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(METADATADB_LIBS) $(top_builddir)/src/libpxtools.la
+pzsearch_SOURCES = \
+    pzsearch.c \
+    pzsearchConfig.c
 
 p0search_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(METADATADB_CFLAGS) $(pxtools_CFLAGS)
Index: /trunk/ippTools/src/pxtools.h
===================================================================
--- /trunk/ippTools/src/pxtools.h	(revision 6658)
+++ /trunk/ippTools/src/pxtools.h	(revision 6659)
@@ -25,4 +25,6 @@
     PX_MODE_DELETE,                     // set the current state
     PX_MODE_RECREATE,                   // set the current state
+    PX_MODE_SEEN,                       // set the current state
+    PX_MODE_COPYDONE,                   // set the current state
 } pxMode;
 
@@ -134,2 +136,4 @@
 rawDetrendFrame *newToRawDetrendFrame(newFrame *newFrame); 
 bool rawDetrendFrameInsert(pxConfig *config, rawDetrendFrame *frame);
+
+bool pzsearchConfig(pxConfig *config, int argc, char **argv);
Index: /trunk/ippTools/src/pztool.c
===================================================================
--- /trunk/ippTools/src/pztool.c	(revision 6659)
+++ /trunk/ippTools/src/pztool.c	(revision 6659)
@@ -0,0 +1,55 @@
+#include <stdlib.h>
+
+#include "pxtools.h"
+
+static bool seenMode(pxConfig *config);
+static bool pendingMode(pxConfig *config);
+static bool copydoneMode(pxConfig *config);
+
+int main(int argc, char **argv)
+{
+    pxConfig *config = pxConfigAlloc();
+
+    pzsearchConfig(config, argc, argv);
+
+    switch (config->mode) {
+        case PX_MODE_SEEN:
+            if (!seenMode(config)) {
+                goto FAIL;
+            }
+            break;
+        case PX_MODE_PENDING:
+            if (!pendingMode(config)) {
+                goto FAIL;
+            }
+            break;
+        case PX_MODE_COPYDONE:
+            if (!copydoneMode(config)) {
+                goto FAIL;
+            }
+            break;
+        default:
+            psAbort(argv[0], "invalid option (this should not happen)");
+    }
+
+    exit(EXIT_SUCCESS);
+
+FAIL:
+    psFree(config);
+    exit(EXIT_FAILURE);
+}
+
+static bool seenMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+}
+
+static bool pendingMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+}
+
+static bool copydoneMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+}
Index: /trunk/ippTools/src/pztoolConfig.c
===================================================================
--- /trunk/ippTools/src/pztoolConfig.c	(revision 6659)
+++ /trunk/ippTools/src/pztoolConfig.c	(revision 6659)
@@ -0,0 +1,196 @@
+#include <pmConfig.h>
+
+#include "pxtools.h"
+
+bool pzsearchConfig(pxConfig *config, int argc, char **argv) {
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    if (! pmConfigRead(&config->site, &config->camera, &config->recipe, &argc, argv, RECIPE)) {
+        psError(PS_ERR_UNKNOWN, false, "Can't find site configuration!\n");
+        exit(EXIT_FAILURE);
+    }
+
+    int N;
+    config->mode = PX_MODE_NONE;
+    if ((N = psArgumentGet (argc, argv, "-seen"))) {
+        psArgumentRemove (N, &argc, argv);
+        if (config->mode) {
+            psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed");
+        }
+        config->mode = PX_MODE_SEEN;
+    }
+    if ((N = psArgumentGet (argc, argv, "-pending"))) {
+        psArgumentRemove (N, &argc, argv);
+        if (config->mode) {
+            psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed");
+        }
+        config->mode = PX_MODE_PENDING;
+    }
+    if ((N = psArgumentGet (argc, argv, "-copydone"))) {
+        psArgumentRemove (N, &argc, argv);
+        if (config->mode) {
+            psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed");
+        }
+        config->mode = PX_MODE_COPYDONE;
+    }
+    
+    // paul's argument parsing convention requires: -key value 
+    // Parse other command-line arguments
+    psMetadata *args = psMetadataAlloc();
+    psMetadataAddStr(args , PS_LIST_TAIL, "-seen", 0,
+        "list all uncopied exposure IDs", "");
+    psMetadataAddStr(args , PS_LIST_TAIL, "-pending",  0,
+        "list all image files pending download", "");
+    psMetadataAddStr(args , PS_LIST_TAIL, "-copydone",  0,
+        "indicate that an image file has been downloaded", "");
+
+    // -pending search
+    /*
+    psMetadata *pendingArgs = psMetadataAlloc();
+    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_id",  0,
+        "define exposure ID", "");
+    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-inst",  0,
+        "define camera of interest", "");
+    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-telescope",  0,
+        "define camera of interest", "");
+    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-exp_type",  0,
+        "define class", "");
+    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-class",  0,
+        "define class", "");
+    */
+
+    bool argErr = false;
+    if (config->mode == PX_MODE_NONE) {
+        argErr = true;
+        fprintf (stderr, "mode argument is required\n");
+    } else if (! psArgumentParse(args, &argc, argv) || argc != 1) {
+        argErr = true;
+        fprintf (stderr, "error parsing arguments\n");
+    }
+
+    if (argErr) {
+        printf("\nPan-STARRS Phase Z Search Tool\n");
+        printf("Usage: %s <mode> [<options>]\n\n", argv[0]);
+        printf(" <mode> : -seen | -pending | -copydone\n\n");
+        /*
+        fprintf (stdout, "-pending ");
+        psArgumentHelp(pendingArgs);
+        fprintf (stdout, "-update ");
+        psArgumentHelp(updateArgs);
+        */
+        psFree(args);
+        /*
+        psFree(pendingArgs);
+        psFree(updateArgs);
+        */
+        exit(EXIT_FAILURE);
+    }
+
+    // XXX why is "" being returned when -[foo] isn't specified?
+#define EMPTY_TO_NULL_STRING(var) \
+    if (var != NULL && strcmp(var, "") == 0) { \
+        var = NULL; \
+    }
+
+    /*
+    switch (config->mode) {
+        bool status;
+        case PX_MODE_PENDING:
+            // -exp_id
+            config->exp_id = psMetadataLookupStr(&status, args, "-exp_id");
+            psMemIncrRefCounter(config->exp_id);
+            EMPTY_TO_NULL_STRING(config->exp_id);
+            // -inst
+            config->camera_name = psMetadataLookupStr(&status, args, "-inst");
+            psMemIncrRefCounter(config->camera_name);
+            EMPTY_TO_NULL_STRING(config->camera_name);
+            // -telescope
+            config->camera_name = psMetadataLookupStr(&status, args,
+                "-telescope");
+            psMemIncrRefCounter(config->telescope);
+            EMPTY_TO_NULL_STRING(config->telescope);
+            // -exp_type
+            config->class = psMetadataLookupStr(&status, args, "-exp_type");
+            psMemIncrRefCounter(config->exp_type);
+            EMPTY_TO_NULL_STRING(config->exp_type);
+            // -class
+            config->class = psMetadataLookupStr(&status, args, "-class");
+            psMemIncrRefCounter(config->class);
+            EMPTY_TO_NULL_STRING(config->class);
+            break;
+        case PX_MODE_UPDATE:
+            // -exp_id
+            config->exp_id = psMetadataLookupStr(&status, args, "-exp_id");
+            psMemIncrRefCounter(config->exp_id);
+            EMPTY_TO_NULL_STRING(config->exp_id);
+            // -filter
+            config->filter = psMetadataLookupStr(&status, args, "-filter");
+            psMemIncrRefCounter(config->filter);
+            EMPTY_TO_NULL_STRING(config->filter);
+
+            break;
+        default:
+            psAbort(argv[0], "invalid option (this should not happen)");
+    }
+    */
+
+    psFree(args);
+    /*
+    psFree(pendingArgs);
+    psFree(updateArgs);
+    */
+
+
+    psMetadata *where = psMetadataAlloc();
+
+    /*
+    if (config->camera_name != NULL) {
+        if (!psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, "==",
+            config->camera_name)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item camera");
+            psFree(where);
+            return NULL;
+        }
+    }
+    if (config->filter != NULL) {
+        psMetadataAddStr(where, PS_LIST_TAIL, "filter", 0, "==",
+            config->filter);
+    }
+    if (config->exp_id != NULL) {
+        psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==",
+            config->exp_id);
+    }
+    if (config->class != NULL) {
+        psMetadataAddStr(where, PS_LIST_TAIL, "class", 0, "==",
+            config->class);
+    }
+    if (config->class_id != NULL) {
+        psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==",
+             config->class_id);
+    }
+    */
+
+    /*
+    // psMetadataConfig does not support times yet
+    if (!psTimeIsZero(config->start) && !psTimeIsZero(config->stop)) {
+        psMetadataAddTime (where, PS_LIST_TAIL, "TIME_START", 0, "<", config->stop);
+        psMetadataAddTime (where, PS_LIST_TAIL, "TIME_STOP", 0, ">", config->start);
+    }
+    */
+
+    if (where->list->n < 1) {
+        psFree(where);
+        where = NULL;
+    }
+
+    config->where = where;
+
+
+    // add the input and output images to the args list
+    //psMetadataAddStr (args, PS_LIST_TAIL, "-output", 0, "Name of the output image", argv[1]);
+
+    // define Database handle, if used
+    config->dbh = pmConfigDB(config->site);
+
+    return true;
+} 
