Index: trunk/pstamp/src/.cvsignore
===================================================================
--- trunk/pstamp/src/.cvsignore	(revision 16132)
+++ trunk/pstamp/src/.cvsignore	(revision 16239)
@@ -6,5 +6,5 @@
 config.h.in
 stamp-h1
-ppstampErrorCodes.c
-ppstampErrorCodes.h
+pstampErrorCodes.c
+pstampErrorCodes.h
 .libs
Index: trunk/pstamp/src/ppstampArguments.c
===================================================================
--- trunk/pstamp/src/ppstampArguments.c	(revision 16132)
+++ trunk/pstamp/src/ppstampArguments.c	(revision 16239)
@@ -5,4 +5,5 @@
 #include "ppstamp.h"
 #include "ppstampOptions.h"
+#include <ctype.h>
 
 static void usage (void)
Index: trunk/pstamp/src/ppstampMakeStamp.c
===================================================================
--- trunk/pstamp/src/ppstampMakeStamp.c	(revision 16132)
+++ trunk/pstamp/src/ppstampMakeStamp.c	(revision 16239)
@@ -454,5 +454,5 @@
         // If the user specified a name of a chip name wait until we get to that one.
         // If no chip name was specified, select this one (the first one that had data)
-        if ((options->chipName == NULL) || !strcmp(chipName, options->chipName)) {
+        if ((options->chipName == NULL) || !strcasecmp(chipName, options->chipName)) {
             psLogMsg("ppstampMakeStamp", 2, "Center on chip: %s\n", chipName);
             center->chip->x = options->roip.centerX;
Index: trunk/pstamp/src/pstamp.h
===================================================================
--- trunk/pstamp/src/pstamp.h	(revision 16132)
+++ trunk/pstamp/src/pstamp.h	(revision 16239)
@@ -22,4 +22,15 @@
 } pstampImageType;
 
+
+// command modes for pstampparse 
+typedef enum {
+    PSP_MODE_UNKNOWN = 0,
+    PSP_MODE_QUEUE_JOB,
+    PSP_MODE_LIST_URI,
+    PSP_MODE_LIST_JOB
+} pspMode;
+
+
+
 #define STAMP_REQUEST_EXTNAME "PS1_PS_REQUEST"
 #define STAMP_REQUEST_VERSION "1.0"
Index: trunk/pstamp/src/pstampparse.c
===================================================================
--- trunk/pstamp/src/pstampparse.c	(revision 16132)
+++ trunk/pstamp/src/pstampparse.c	(revision 16239)
@@ -11,7 +11,9 @@
     psString    fileName;
     psMetadata  *md;
-    psString    commandLine;
     psString    roiString;
+    pspMode     mode;
+    bool        verbose;
 } pspOptions;
+
 
 static void usage()
@@ -22,13 +24,31 @@
 }
 
+static pspMode parseMode(char *modeString)
+{
+    pspMode mode = PSP_MODE_UNKNOWN;
+
+    if (!strcasecmp(modeString, "list_uri")) {
+        mode = PSP_MODE_LIST_URI;
+    } else if (!strcasecmp(modeString, "list_job")) {
+        mode = PSP_MODE_LIST_JOB;
+    } else if (!strcasecmp(modeString, "queue_job")) {
+        mode = PSP_MODE_QUEUE_JOB;
+    } else {
+        fprintf(stderr, "unknown command mode: %s\n", modeString);
+        exit(1);
+    }
+    return mode;
+}
+
 
 static pspOptions *parseArguments(int argc, char *argv[])
 {
+    int argnum;
     pspOptions *options = psAlloc(sizeof(pspOptions));
+
     memset(options, 0, sizeof(*options));
-    // int         argnum;
 
     // options to add
-    //      mode:   -queuejobs -execute -preview
+    //      mode:   -queuejobs -execute
 
     options->config = pmConfigRead(&argc, argv, NULL);
@@ -37,4 +57,20 @@
         psFree(options);
         return NULL;
+    }
+
+    if ((argnum = psArgumentGet(argc, argv, "-mode"))) {
+        options->verbose = true;
+        psArgumentRemove(argnum, &argc, argv);
+        if (argnum == argc) {
+            fprintf(stderr, "value required for mode\n");
+            usage();
+        }
+        options->mode = parseMode(argv[argnum]);
+        psArgumentRemove(argnum, &argc, argv);
+    }
+
+    if ((argnum = psArgumentGet(argc, argv, "-verbose"))) {
+        options->verbose = true;
+        psArgumentRemove(argnum, &argc, argv);
     }
 
@@ -57,5 +93,5 @@
 }
 
-static bool readTable(pspOptions *options)
+static bool readRequestTable(pspOptions *options)
 {
     psFits *fitsFile = psFitsOpen(options->fileName, "r");
@@ -180,10 +216,10 @@
             psString val = psMetadataLookupStr(NULL, row, target);
             if (val != 0) {
-                output = psArrayAdd(output, len -i, val);
+                output = psArrayAdd(output, len - i, val);
             }
         } else {
             psU64 val = psMetadataLookupU64(NULL, row, target);
             if (val != 0) {
-                output = psArrayAdd(output, len -i, idToStr(val));
+                output = psArrayAdd(output, len - i, idToStr(val));
             }
         }
@@ -303,6 +339,8 @@
 
     psString warp_id = warpIDForCam(options, cam_id);
-
-    psArray *stackIDs = runQuery(options, "SELECT %%S FROM stackInputSkyfile WHERE warp_id = %s",
+    if (warp_id == NULL)
+        return NULL;
+
+    psArray *stackIDs = runQuery(options, "SELECT %s FROM stackInputSkyfile WHERE warp_id = %s",
                             "stack_id", warp_id, NULL, false, NULL);
 
@@ -500,5 +538,5 @@
             return NULL;
         }
-        psStringAppend(&roiString, " -skycenter %s %s", ra, dec);
+        psStringAppend(&roiString, "-skycenter %s %s", ra, dec);
     } else {
         psString x = psMetadataLookupStr(&status, options->md, "CENTER_X");
@@ -507,6 +545,6 @@
             return NULL;
         }
-        psString y = psMetadataLookupStr(&status, options->md, "CENTER_X");
-        psStringAppend(&roiString, " -pixcenter %s %s", x, y);
+        psString y = psMetadataLookupStr(&status, options->md, "CENTER_Y");
+        psStringAppend(&roiString, "-pixcenter %s %s", x, y);
     }
 
@@ -533,8 +571,20 @@
 
 static bool
-parseTable(pspOptions *options)
-{
+parseRequestTable(pspOptions *options)
+{
+    bool status;
+    psString cmd_mode = psMetadataLookupStr(&status, options->md, "CMD_MODE");
+
+    // if mode is set on the command line ignore the value in the request file
+    if (options->mode == PSP_MODE_UNKNOWN) {
+        if (cmd_mode != NULL) {
+            options->mode = parseMode(cmd_mode);
+        } else {
+            options->mode = PSP_MODE_LIST_JOB;
+        }
+    }
+
     // how are we to select the images ?
-    psString req_type = psMetadataLookupStr(NULL, options->md, "REQ_TYPE");
+    psString req_type = psMetadataLookupStr(&status, options->md, "REQ_TYPE");
 
     if ( !req_type) {
@@ -566,34 +616,35 @@
     if (uris == NULL) {
         // may need a finer grained status code: did something go wrong with the system
-        // or are there just no images matching the request
+        // or are there simply no images matching the request
+        fprintf(stderr, "No matching images found.\n");
+        return true;
+    }
+
+    int numURIs = psArrayLength(uris);
+    if (options->mode == PSP_MODE_LIST_URI) {
+        for (int i=0; i<numURIs; i++) {
+            fprintf(stdout, "%s\n", (psString) uris->data[i]);
+        }
+    } else if (options->mode == PSP_MODE_LIST_JOB) {
+        psString commandArgs = roiString;
+        psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
+        if (class_id) {
+            psStringAppend(&commandArgs, " -chip %s", class_id); 
+        }
+
+        psString user_tag = psMetadataLookupStr(&status, options->md, "USER_TAG");
+        if (user_tag == NULL) {
+            psError(PS_ERR_UNKNOWN, true, "no user tag in request file");
+            return false;
+        }
+
+        for (int i = 0; i < numURIs; i++) {
+            printf("%s %s %s\n", (psString) uris->data[i], user_tag, commandArgs);
+        }
+    } else {
+        fprintf(stderr, "PSP_MODE_QUEUE_JOB not implemented yet\n");
         return false;
     }
 
-    int len = psArrayLength(uris);
-    fprintf(stderr, "URIS:\n");
-    for (int i=0; i<len; i++) {
-        fprintf(stderr, "  %3d %s\n", i, (psString) uris->data[i]);
-    }
-
-#ifdef notyet
-    // XXX: We need more than a single command line since we might have multiple images
-    psStringAppend(&options->commandLine, "ppstamp ");
-
-    // For now just take the last image returned as the Image of interest
-    psString imageFile = uris->data[psArrayLength(uris) - 1];
-
-    psStringAppend(&options->commandLine, " -file %s", imageFile);
-
-    // Set the output file name to user_tag.fits
-    psString user_tag = psMetadataLookupStr(NULL, options->md, "USER_TAG");
-    if (user_tag == NULL) {
-        psError(PS_ERR_UNKNOWN, true, "no user tag in request file");
-        return false;
-    }
-
-    // XXX: need configurable output directory: get from database, recipe, site file, command line arg?
-
-    psStringAppend(&options->commandLine, " %s.fits", user_tag); 
-#endif
 
     return true;
@@ -603,5 +654,4 @@
 {
     pspOptions *options = parseArguments(argc, argv);
-    bool verbose = true;
 
     // XXX: create a set of status codes to return so the
@@ -617,5 +667,5 @@
     }
 
-    if (!readTable(options)) {
+    if (!readRequestTable(options)) {
         return 1;
     }
@@ -625,25 +675,13 @@
     }
 
-    if (verbose) {
+    if (options->verbose) {
         psMetadataPrint(stderr, options->md, 0);
     }
 
-    if (!parseTable(options)) {
-        psErrorStackPrint(stderr, "unable to parse request table");
+    if (!parseRequestTable(options)) {
+        // psErrorStackPrint(stderr, "unable to parse request table");
         return 1;
     }
 
-    // XXX: We need to have multiple modes of operation depending on command line options
-    //      1. add a job to the database.
-    //      2. print the ppstamp command line
-    //      3. execute the command
-    // Actually should probably just let pstampparse do the last one so as
-    // to keep the ippTools model for database interactions intact. 
-    // So far in this program I'm only doing reads from the database not edits.
-
-    if (options->commandLine) {
-        printf("%s\n", options->commandLine);
-    }
-
     return 0;
 }
Index: trunk/pstamp/src/pstamprequest.c
===================================================================
--- trunk/pstamp/src/pstamprequest.c	(revision 16132)
+++ trunk/pstamp/src/pstamprequest.c	(revision 16239)
@@ -334,5 +334,10 @@
     }
 
-    // TODO: find other optional arguments
+    if ((argnum = psArgumentGet(argc, argv, "-list"))) {
+        psMetadataAdd (options->md, PS_LIST_TAIL, "CMD_MODE", PS_DATA_STRING, "", "LIST_URI");
+        psArgumentRemove(argnum, &argc, argv);
+    }
+
+    // only argument left should be the required file name for the request file
 
     if (argc == 2) {
