Index: /trunk/pstamp/src/pstampparse.c
===================================================================
--- /trunk/pstamp/src/pstampparse.c	(revision 18378)
+++ /trunk/pstamp/src/pstampparse.c	(revision 18379)
@@ -1,4 +1,4 @@
-// pstampparse  - read a fits table describing a postage stamp request and prepare the request
-// for processing
+// pstampparse ---> imagetool but this program is going to be
+// deleted so we'll just leave the external name alone
 
 #include <pslib.h>
@@ -6,18 +6,31 @@
 #include <string.h>
 #include <strings.h>
-#include "pstamp.h"
-#include "pstampROI.h"
+
+typedef enum {
+    UNKNOWN_IMAGE = -1,
+    RAW_IMAGE,
+    CHIP_IMAGE,
+    WARP_IMAGE,
+    STACK_IMAGE,
+    DIFF_IMAGE
+} itImageType;
+
+typedef enum {
+    BY_ID,
+    BY_EXP,
+    BY_COORD,
+    UNKNOWN_LOOKUP_TYPE
+} itLookupType;
 
 typedef struct {
-    pmConfig    *config;
-    psString    fileName;
-    psString    outputDirectory;
-    psMetadata  *md;
-    psString    roiString;
-    pspMode     mode;
-    psS64       req_id;
-    bool        verbose;
-    bool        simple;
-} pspOptions;
+    pmConfig        *config;
+    itLookupType    lookupType;
+    itImageType     imageType;
+    psString        id;
+    psString        class_id;
+    psString        roiString;
+    bool            verbose;
+    bool            simple;
+} itOptions;
 
 
@@ -25,35 +38,65 @@
 {
     // XXX: fill this out
-    fprintf(stderr, "argument error\n");
+    psErrorStackPrint(stderr, "argument error");
     exit(1);
 }
 
-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;
+static itImageType parseImageType(psString type)
+{
+    itImageType itype;
+
+    if (type == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "NULL image type");
+        itype = UNKNOWN_IMAGE;
+        return itype;
+    }
+
+    if (strcmp(type, "raw") == 0) {
+        itype = RAW_IMAGE;
+    } else if (strcmp(type, "chip") == 0) {
+        itype = CHIP_IMAGE;
+    } else if (strcmp(type, "warp") == 0) {
+        itype = WARP_IMAGE;
+    } else if (strcmp(type, "diff") == 0) {
+        itype = DIFF_IMAGE;
+    } else if (strcmp(type, "stack") == 0) {
+        itype = STACK_IMAGE;
     } else {
-        fprintf(stderr, "unknown command mode: %s\n", modeString);
-        exit(1);
-    }
-    return mode;
-}
-
-
-static pspOptions *parseArguments(int argc, char *argv[])
+        psError(PS_ERR_UNKNOWN, true, "unknown image type %s", type);
+        itype = UNKNOWN_LOOKUP_TYPE;
+    }
+
+    return itype;
+}
+static void getParams(itOptions *options, int argnum, int *pArgc, char *argv[])
+{
+    if (*pArgc < 3) {
+        fprintf(stderr, "values required for type and id\n");
+        usage();
+    }
+
+    options->imageType = parseImageType(argv[argnum]);
+    psArgumentRemove(argnum, pArgc, argv);
+    options->id = argv[argnum];
+    psArgumentRemove(argnum, pArgc, argv);
+
+    if ((options->imageType == RAW_IMAGE) || (options->imageType == CHIP_IMAGE)) {
+        if (*pArgc < 2) {
+            fprintf(stderr, "value required for class_id\n");
+            usage();
+        }
+        options->class_id = argv[argnum];
+    
+        psArgumentRemove(argnum, pArgc, argv);
+    }
+}
+
+static itOptions *parseArguments(int argc, char *argv[])
 {
     int argnum;
-    pspOptions *options = psAlloc(sizeof(pspOptions));
+    itOptions *options = psAlloc(sizeof(itOptions));
+    bool gotLookupType = false;
 
     memset(options, 0, sizeof(*options));
-
-    // options to add
-    //      mode:   -queuejobs -execute
 
     options->config = pmConfigRead(&argc, argv, NULL);
@@ -64,31 +107,35 @@
     }
 
-    // XXX: need to sort out the interactions of this mode option and the JOB_TYPE
-    // listed in the request file.
-    if ((argnum = psArgumentGet(argc, argv, "-mode"))) {
+    if ((argnum = psArgumentGet(argc, argv, "-byid"))) {
+        options->lookupType = BY_ID;
         psArgumentRemove(argnum, &argc, argv);
-        if (argnum == argc) {
-            fprintf(stderr, "value required for mode\n");
+        getParams(options, argnum, &argc, argv);
+        gotLookupType = true;
+    }
+    if ((argnum = psArgumentGet(argc, argv, "-byexp"))) {
+        if (gotLookupType) {
+            psError(PS_ERR_UNKNOWN, false, "only one of -byid, -byexp, and -bycoord may be used\n");
             usage();
         }
-        options->mode = parseMode(argv[argnum]);
+        gotLookupType = true;
+        options->lookupType = BY_EXP;
         psArgumentRemove(argnum, &argc, argv);
-    } else {
-        options->mode = PSP_MODE_LIST_JOB;
-    }
-
-    if ((argnum = psArgumentGet(argc, argv, "-req_id"))) {
+        getParams(options, argnum, &argc, argv);
+    }
+    if ((argnum = psArgumentGet(argc, argv, "-bycoord"))) {
+        if (gotLookupType) {
+            psError(PS_ERR_UNKNOWN, false, "only one of -byid, -byexp, and -bycoord may be used\n");
+            usage();
+        }
         psArgumentRemove(argnum, &argc, argv);
-        if (argnum == argc) {
-            fprintf(stderr, "value required for req_id\n");
-            usage();
-        }
-        options->req_id = atol(argv[argnum]);
-        psArgumentRemove(argnum, &argc, argv);
-    }
-
-    if ((options->mode == PSP_MODE_QUEUE_JOB) && (options->req_id <= 0)) {
-        psError(PS_ERR_UNKNOWN, true, "need request id in order to queue jobs\n");
-        return false;
+        gotLookupType = true;
+        options->lookupType = BY_COORD;
+        getParams(options, argnum, &argc, argv);
+        psError(PS_ERR_UNKNOWN, true, "REQ_TYPE: bycoord not implemented yet");
+        return NULL;
+    }
+    if (!gotLookupType) {
+        psError(PS_ERR_BAD_PARAMETER_NULL , true, "one of -byid, -byexp, or -bycoord must be supplied\n");
+        usage();
     }
 
@@ -102,22 +149,11 @@
         psArgumentRemove(argnum, &argc, argv);
     }
-    if ((argnum = psArgumentGet(argc, argv, "-out_dir"))) {
-        psArgumentRemove(argnum, &argc, argv);
-        if (argnum == argc) {
-            fprintf(stderr, "value required for out_dir\n");
-            usage();
-        }
-        options->outputDirectory = argv[argnum];
-        psArgumentRemove(argnum, &argc, argv);
-    }
-
-    if (argc == 2) {
-        options->fileName = psStringCopy(argv[1]);
-    } else if (argc == 1) {
-        fprintf(stderr, "input file name is required\n");
-        usage();
-    } else {
-        fprintf(stderr, "unknown arguments supplied:");
-        fprintf(stderr, " %s", argv[1]);
+
+    // XXX: Arguments to add for bycoord searches FILTER, DATE_BEGIN, DATE_END
+
+    if (argc > 1) {
+        fprintf(stderr, "unknown arguments supplied: ");
+
+        fprintf(stderr, "%s", argv[1]);
         for (int i=2; i<argc; i++) {
             fprintf(stderr, ", %s", argv[i]);
@@ -130,27 +166,5 @@
 }
 
-static bool readRequestTable(pspOptions *options)
-{
-    psFits *fitsFile = psFitsOpen(options->fileName, "r");
-    if (fitsFile == NULL) {
-        psError(PS_ERR_IO, false, "failed to open %s for output", options->fileName);
-        return false;
-    }
-
-    psArray *array = psFitsReadTable(fitsFile);
-
-    psFitsClose(fitsFile);
-
-    if (array == NULL) {
-        psError(PS_ERR_IO, false, "psFitsReadTable failed for %s", options->fileName);
-        return false;
-    }
-
-    options->md = array->data[0];
-
-    return true;
-}
-
-static bool setupDB(pspOptions *options)
+static bool setupDB(itOptions *options)
 {
     // XXX: need to select the database name based on the project name specified in the input
@@ -166,33 +180,4 @@
 }
 
-// TODO: move this to a shared file
-static pstampImageType getImageType(pspOptions *options)
-{
-    psString type = psMetadataLookupStr(NULL, options->md, "IMG_TYPE");
-    pstampImageType itype;
-
-    if (type == NULL) {
-        psError(PS_ERR_UNKNOWN, true, "NULL image type");
-        itype = PSTAMP_UNKNOWN;
-        return itype;
-    }
-
-    if (strcmp(type, "raw") == 0) {
-        itype = PSTAMP_RAW;
-    } else if (strcmp(type, "chip") == 0) {
-        itype = PSTAMP_CHIP;
-    } else if (strcmp(type, "warp") == 0) {
-        itype = PSTAMP_WARP;
-    } else if (strcmp(type, "diff") == 0) {
-        itype = PSTAMP_DIFF;
-    } else if (strcmp(type, "stack") == 0) {
-        itype = PSTAMP_STACK;
-    } else {
-        psError(PS_ERR_UNKNOWN, true, "unknown image type %s", type);
-        itype = PSTAMP_UNKNOWN;
-    }
-
-    return itype;
-}
 
 // return a string with the contents of a unsigned 64 bit value
@@ -211,5 +196,5 @@
 // the type for the values returned by the query is either a string or psU64.
 
-static psArray *runQuery(pspOptions *options, psString query, psString target,
+static psArray *runQuery(itOptions *options, psString query, psString target,
                 psString key1, psString key2, bool targetIsString, psArray *output)
 {
@@ -268,5 +253,5 @@
 }
 
-static psArray *findURIs(pspOptions *options, psString table, psString id_type, psString id, psString class_id)
+static psArray *findURIs(itOptions *options, psString table, psString id_type, psString id, psString class_id)
 {
     psString query = NULL;
@@ -325,5 +310,5 @@
 
 
-static psArray *findChipURIs(pspOptions *options, psString exp_id, psString class_id)
+static psArray *findChipURIs(itOptions *options, psString exp_id, psString class_id)
 {
     psString chip_id = chipIDForExp(options, exp_id);
@@ -340,5 +325,5 @@
 }
 
-static psArray *findWarpURIs(pspOptions *options, psString exp_id)
+static psArray *findWarpURIs(itOptions *options, psString exp_id)
 {
     psString chip_id = chipIDForExp(options, exp_id);
@@ -365,5 +350,5 @@
 }
 
-static psArray *findStackURIs(pspOptions *options, psString exp_id)
+static psArray *findStackURIs(itOptions *options, psString exp_id)
 {
     psString chip_id = chipIDForExp(options, exp_id);
@@ -406,5 +391,5 @@
 }
 
-static psArray *findDiffURIs(pspOptions *options, psString exp_id)
+static psArray *findDiffURIs(itOptions *options, psString exp_id)
 {
     psString chip_id = chipIDForExp(options, exp_id);
@@ -446,10 +431,8 @@
 }
 
-static psArray * parseByID(pspOptions *options)
-{
-    bool status = false;
-    pstampImageType itype = getImageType(options);
-    psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
-    psString id = psMetadataLookupStr(NULL, options->md, "ID");
+static psArray * parseByID(itOptions *options)
+{
+    psString id = options->id;
+    psString class_id = options->class_id;
     psArray *uris = NULL;
 
@@ -459,22 +442,22 @@
     }
 
-    switch (itype) {
-    case PSTAMP_RAW:
+    switch (options->imageType) {
+    case RAW_IMAGE:
         uris = findURIs(options, "rawImfile", "exp_id", id, class_id);
         break;
-    case PSTAMP_CHIP:
+    case CHIP_IMAGE:
         uris = findURIs(options, "chipProcessedImfile", "chip_id", id, class_id);
         break;
-    case PSTAMP_WARP:
+    case WARP_IMAGE:
         uris = findURIs(options, "warpSkyfile", "warp_id", id, NULL);
         break;
-    case PSTAMP_DIFF:
+    case DIFF_IMAGE:
         uris = findURIs(options, "diffSkyfile", "diff_id", id, NULL);
         break;
-    case PSTAMP_STACK:
+    case STACK_IMAGE:
         uris = findURIs(options, "stackSumSkyfile", "stack_id", id, NULL);
         break;
     default:
-        // note: getImageType prints a message
+        // note: parseImageType prints a message
         return NULL;
     }
@@ -491,5 +474,5 @@
 }
 
-psString exposureNameToID(pspOptions *options, psString exposure)
+psString exposureNameToID(itOptions *options, psString exposure)
 {
     psArray *results;
@@ -501,11 +484,8 @@
 }
 
-static psArray * parseByExp(pspOptions *options)
-{
-    // psError(PS_ERR_UNKNOWN, true, "REQ_TYPE: byexp not implemented yet");
-    bool status = false;
-    pstampImageType itype = getImageType(options);
-    psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
-    psString exposure = psMetadataLookupStr(NULL, options->md, "EXPOSURE");
+static psArray * parseByExp(itOptions *options)
+{
+    psString class_id = options->class_id;
+    psString exposure = options->id;
     psArray *uris = NULL;
 
@@ -520,6 +500,6 @@
     }
 
-    switch (itype) {
-    case PSTAMP_RAW:
+    switch (options->imageType) {
+    case RAW_IMAGE:
         if (class_id == NULL) {
             // XXX: we could relax this requirement if roi is specified in sky coords and
@@ -530,5 +510,5 @@
         uris = findURIs(options, "rawImfile", "exp_id", exp_id, class_id);
         break;
-    case PSTAMP_CHIP:
+    case CHIP_IMAGE:
         if (class_id == NULL) {
             // XXX: we could relax this requirement if roi is specified in sky coords and
@@ -539,15 +519,15 @@
         uris = findChipURIs(options, exp_id, class_id);
         break;
-    case PSTAMP_WARP:
+    case WARP_IMAGE:
         uris = findWarpURIs(options, exp_id);
         break;
-    case PSTAMP_DIFF:
+    case DIFF_IMAGE:
         uris = findDiffURIs(options, exp_id);
         break;
-    case PSTAMP_STACK:
+    case STACK_IMAGE:
         uris = findStackURIs(options, exp_id);
         break;
     default:
-        // note: getImageType prints an error message
+        // note: parseImageType prints an error message
         return NULL;
     }
@@ -558,15 +538,15 @@
 }
 
-static psArray * parseByCoord(pspOptions *options)
-{
-    psError(PSTAMP_ERR_NOT_IMPLEMENTED, true, "REQ_TYPE: bycoord not implemented yet");
+static psArray * parseByCoord(itOptions *options)
+{
+    psError(PS_ERR_UNKNOWN, true, "REQ_TYPE: bycoord not implemented yet");
     return NULL;
 }
 
-static psString parseROI(pspOptions *options)
-{
+static psString parseROI(itOptions *options)
+{
+    psString roiString = NULL;
+#ifdef notyet
     bool status = false;;
-    psString roiString = NULL;
-
     psU32 coord_mask = psMetadataLookupU32(&status, options->md, "COORD_MASK");
     if (!status) {
@@ -609,147 +589,13 @@
     }
 
+#endif
     return roiString;
 }
 
 static bool
-queueOneJob (pspOptions *options, psString job_type, psString uri, psString outputBase, psString commandArgs)
-{
-    psString cmd = NULL;
-
-    psStringAppend(&cmd, "pstamptool -addjob -req_id %" PRId64 " -job_type %s -uri %s ",
-        options->req_id, job_type, uri);
-
-    if (outputBase != NULL) {
-        psStringAppend(&cmd, "-outputBase ");
-
-        if (options->outputDirectory) {
-            psStringAppend(&cmd, "%s/", options->outputDirectory);
-        }
-        psStringAppend(&cmd, "%s", outputBase);
-    }
-    if (commandArgs) {
-        psStringAppend(&cmd, " -args '%s'", commandArgs);
-    }
-    // XXX We may want to have the data store name be different than the default DB
-    psBool status;
-    psString dbName = psMetadataLookupStr(&status, options->config->complete, "DBNAME");
-    fprintf(stderr, "\n\n   dbName is %s\n", dbName);
-    if (dbName) {
-        psStringAppend(&cmd, " -dbname %s", dbName);
-    }
-
-    psStringAppend(&cmd, " > /dev/null");
-
-    if (options->verbose) {
-        fprintf(stderr, "excuting system(%s)\n", cmd);
-    }
-
-    int rstatus = system(cmd);
-
-    if (rstatus) {
-        fprintf(stderr, "%s failed with status: %d\n", cmd, rstatus);
-    }
-    psFree(cmd);
-
-    // TODO: should we be returning the exit status so that it can be reported?
-    return !rstatus;
-}
-
-static bool
-queueJobs (pspOptions *options, psString job_type, psArray *uris, psString stamp_name, psString commandArgs)
-{
-    int numURIs = psArrayLength(uris);
-    bool status = false;
-
-    if (numURIs == 1) {
-        // use the user tag as the outputBase
-        status = queueOneJob(options, job_type, uris->data[0], stamp_name, commandArgs);
-    } else {
-        for (int i = 0; i< numURIs; i++) {
-            psString outputBase = NULL;
-
-            // append an integer to the stamp_name to get a uniqueu outputBase
-            psStringAppend(&outputBase, "%s_%d", stamp_name, i);
-
-            status = queueOneJob(options, job_type, uris->data[i], outputBase, commandArgs);
-            psFree(outputBase);
-
-            if (!status) {
-                break;
-            }
-        }
-    }
-
-    return status;
-}
-
-static bool
-turnOnResultsFile(pspOptions *options)
-{
-    // turn off the creation of a results file for this request
-    char * query = "UPDATE pstampRequest SET resultsFile = 1 WHERE req_id = %" PRId64;
-    return p_psDBRunQuery(options->config->database, query, options->req_id);
-}
-
-static bool
-queueGetImageJob(pspOptions *options, psArray *uris, psString req_type)
-{
-    FILE        *listFile;
-    psString    fileName = NULL;
-    psString    img_type = psMetadataLookupStr(NULL, options->md, "IMG_TYPE");
-
-#ifdef notdef
-    if (! turnOffResultsFile(options)) {
-        fprintf(stderr, "failed to update resultsFile for request %" PRId64 "\n", options->req_id);
-        return false;
-    }
-#endif
-
-    if (options->outputDirectory == NULL) {
-        fprintf(stderr, "outputDirectory is required\n");
-        return false;
-    }
-    psStringAppend(&fileName, "%s/filelist", options->outputDirectory);
-
-    listFile = fopen(fileName, "w");
-    if (listFile == NULL) {
-        psError(PS_ERR_UNKNOWN, true, "failed to open get_image file list: %s\n", fileName);
-        return false;
-    }
-
-    for (int i=0; i<psArrayLength(uris); i++) {
-        fprintf(listFile, "%s|%s\n", (psString) uris->data[i], img_type);
-    }
-    fclose(listFile);
-
-    psString cmd = NULL;
-    psStringAppend(&cmd, "pstamptool -addjob -req_id %" PRId64 " -job_type get_image -uri %s -outputBase %s",
-        options->req_id, fileName, options->outputDirectory);
-
-    int rstatus = system(cmd);
-    if (rstatus) {
-        fprintf(stderr, "%s failed with status: %d\n", cmd, rstatus);
-    }
-
-    return rstatus == 0;
-}
-
-
-static bool
-parseRequestTable(pspOptions *options)
-{
-    bool status = false;
-
-    psString job_type = psMetadataLookupStr(&status, options->md, "JOB_TYPE");
-    if (job_type == NULL) {
-        psError(PS_ERR_UNKNOWN, true, "bad request file: JOB_TYPE not specified");
-        return false;
-    }
-
-    bool isStampJob = (strcmp(job_type, "stamp") == 0);
-
+go(itOptions *options)
+{
     // how are we to select the images ?
-    psString req_type = psMetadataLookupStr(&status, options->md, "REQ_TYPE");
-    if ( !req_type) {
+    if (options->lookupType == UNKNOWN_LOOKUP_TYPE) {
         psError(PS_ERR_UNKNOWN, true, "request file has no REQ_TYPE");
         return false;
@@ -757,30 +603,26 @@
 
     psString roiString = parseROI(options);
-    if (isStampJob && !roiString) {
-        psError(PS_ERR_UNKNOWN, false, "need valid ROI for stamp request");
-        return false;
-    }
 
     psArray *uris = NULL;
 
-    if (!strcmp(req_type, "byid")) {
+    switch (options->lookupType) {
+    case BY_ID:
         // directly by exp_id, chip_id, warp_id etc
-
         uris = parseByID(options);
-    } else if (!strcmp(req_type, "byexp")) {
+        break;
+    case BY_EXP:
         // images that resulted from a given exposure
-
         uris = parseByExp(options);
-    } else if (!strcmp(req_type, "bycoord")) {
+        break;
+    case BY_COORD:
         // images from a particular region of the sky
-
         if (!roiString) {
-            fprintf(stderr, "Region of interest required with req_type: bycoord\n");
+            fprintf(stderr, "Region of interest required with lookupType: bycoord\n");
             return false;
         }
         uris = parseByCoord(options);
-    } else {
-
-        psError(PS_ERR_UNKNOWN, true, "unknown REQ_TYPE: %s", req_type);
+        break;
+    default:
+        psError(PS_ERR_PROGRAMMING, true, "unknown Lookup type: %d\n", options->lookupType);
         return false;
     }
@@ -790,67 +632,12 @@
         // or are there simply no images matching the request
         fprintf(stderr, "No matching images found.\n");
-        return false;
+        // don't return an error
+        return true;
     }
 
     int numURIs = psArrayLength(uris);
-    if (options->mode == PSP_MODE_LIST_URI) {
-        // Just list the images that would have jobs queued for them
-        for (int i=0; i<numURIs; i++) {
-            fprintf(stdout, "%s\n", (psString) uris->data[i]);
-        }
-    } else {
-        psString commandArgs = roiString;
-        psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
-        // We don't check here whether class_id is required. We leave that up to
-        // ppstamp
-        if (class_id && strcmp(class_id, "null")) {
-            // TODO: the ppstamp argument needs to change to class_id
-            // perhaps allow chip as a synonym
-            psStringAppend(&commandArgs, " -chip %s", class_id);
-        }
-        psString stamp_name = psMetadataLookupStr(&status, options->md, "STAMP_NAME");
-
-        if (options->mode == PSP_MODE_LIST_JOB) {
-            if (numURIs == 1) {
-                printf("%s %s %s %s\n", job_type, (psString) uris->data[0],
-                    stamp_name ? stamp_name : "", commandArgs ? commandArgs : "") ;
-            } else {
-                // add an integer to the stamp_name
-                for (int i = 0; i < numURIs; i++) {
-                    printf("%s %s %s_%d %s\n", job_type, (psString) uris->data[i], stamp_name, i,
-                        commandArgs ? commandArgs :"");
-                }
-            }
-        } else if (options->mode == PSP_MODE_QUEUE_JOB) {
-
-            if (!strcmp(job_type, "stamp")) {
-                // Postage stamp job
-                if (stamp_name == NULL) {
-                    psError(PS_ERR_UNKNOWN, true, "no STAMP_NAME in request file");
-                    return false;
-                }
-
-                if (!queueJobs(options, job_type, uris, stamp_name, commandArgs)) {
-                    return false;
-                }
-
-                // Note: This is a DB operation
-                if (!turnOnResultsFile(options)) {
-                    psError(PS_ERR_UNKNOWN, true, "failed to update resultsFile");
-
-                    // TODO: should we unqueue the jobs, set state of request to false??
-                    // Maybe get rid of the column and just use job_type to trigger creation of
-                    // results file. so what if the gui doesn't need it?
-                    return false;
-                }
-            } else {
-                return queueGetImageJob(options, uris, req_type);
-            }
-
-        } else {
-            // this error is actually caught by parseMode
-            fprintf(stderr, "unknown command mode found: %d\n", options->mode);
-            exit(1);
-        }
+    // Just list the images that would have jobs queued for them
+    for (int i=0; i<numURIs; i++) {
+        fprintf(stdout, "%s\n", (psString) uris->data[i]);
     }
 
@@ -860,23 +647,5 @@
 int main(int argc, char *argv[])
 {
-    pspOptions *options = parseArguments(argc, argv);
-
-    // XXX: create a set of status codes to return so the
-    // scripts can distinguish between different errors.
-    // For example:
-    //      If we can't connect to the DB it's a configuration problem.
-    //      If a particular image doesn't contain coordinates specified that's a user "error"
-    //      if there are no images of a particular ROI outside of a date range, that tells us
-    //      something
-
-    if (!options) {
-        psErrorStackPrint(stderr, "unable to parse arguments");
-        return 1;
-    }
-
-    if (!readRequestTable(options)) {
-        psErrorStackPrint(stderr, "unable to read request table");
-        return 1;
-    }
+    itOptions *options = parseArguments(argc, argv);
 
     if (!setupDB(options)) {
@@ -885,10 +654,6 @@
     }
 
-    if (options->verbose) {
-        psMetadataPrint(stderr, options->md, 0);
-    }
-
-    if (!parseRequestTable(options)) {
-        psErrorStackPrint(stderr, "unable to parse request table");
+    if (!go(options)) {
+        psErrorStackPrint(stderr, "error processing request");
         return 1;
     }
