IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18379


Ignore:
Timestamp:
Jun 30, 2008, 10:01:31 AM (18 years ago)
Author:
bills
Message:

Moved most of the functionality from pstampparse to pstampparse.pl
just leaving the image ROI lookup. This will be moved to ippTools soon
and this program will be delted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/src/pstampparse.c

    r18247 r18379  
    1 // pstampparse  - read a fits table describing a postage stamp request and prepare the request
    2 // for processing
     1// pstampparse ---> imagetool but this program is going to be
     2// deleted so we'll just leave the external name alone
    33
    44#include <pslib.h>
     
    66#include <string.h>
    77#include <strings.h>
    8 #include "pstamp.h"
    9 #include "pstampROI.h"
     8
     9typedef enum {
     10    UNKNOWN_IMAGE = -1,
     11    RAW_IMAGE,
     12    CHIP_IMAGE,
     13    WARP_IMAGE,
     14    STACK_IMAGE,
     15    DIFF_IMAGE
     16} itImageType;
     17
     18typedef enum {
     19    BY_ID,
     20    BY_EXP,
     21    BY_COORD,
     22    UNKNOWN_LOOKUP_TYPE
     23} itLookupType;
    1024
    1125typedef struct {
    12     pmConfig    *config;
    13     psString    fileName;
    14     psString    outputDirectory;
    15     psMetadata  *md;
    16     psString    roiString;
    17     pspMode     mode;
    18     psS64       req_id;
    19     bool        verbose;
    20     bool        simple;
    21 } pspOptions;
     26    pmConfig        *config;
     27    itLookupType    lookupType;
     28    itImageType     imageType;
     29    psString        id;
     30    psString        class_id;
     31    psString        roiString;
     32    bool            verbose;
     33    bool            simple;
     34} itOptions;
    2235
    2336
     
    2538{
    2639    // XXX: fill this out
    27     fprintf(stderr, "argument error\n");
     40    psErrorStackPrint(stderr, "argument error");
    2841    exit(1);
    2942}
    3043
    31 static pspMode parseMode(char *modeString)
    32 {
    33     pspMode mode = PSP_MODE_UNKNOWN;
    34 
    35     if (!strcasecmp(modeString, "list_uri")) {
    36         mode = PSP_MODE_LIST_URI;
    37     } else if (!strcasecmp(modeString, "list_job")) {
    38         mode = PSP_MODE_LIST_JOB;
    39     } else if (!strcasecmp(modeString, "queue_job")) {
    40         mode = PSP_MODE_QUEUE_JOB;
     44static itImageType parseImageType(psString type)
     45{
     46    itImageType itype;
     47
     48    if (type == NULL) {
     49        psError(PS_ERR_UNKNOWN, true, "NULL image type");
     50        itype = UNKNOWN_IMAGE;
     51        return itype;
     52    }
     53
     54    if (strcmp(type, "raw") == 0) {
     55        itype = RAW_IMAGE;
     56    } else if (strcmp(type, "chip") == 0) {
     57        itype = CHIP_IMAGE;
     58    } else if (strcmp(type, "warp") == 0) {
     59        itype = WARP_IMAGE;
     60    } else if (strcmp(type, "diff") == 0) {
     61        itype = DIFF_IMAGE;
     62    } else if (strcmp(type, "stack") == 0) {
     63        itype = STACK_IMAGE;
    4164    } else {
    42         fprintf(stderr, "unknown command mode: %s\n", modeString);
    43         exit(1);
    44     }
    45     return mode;
    46 }
    47 
    48 
    49 static pspOptions *parseArguments(int argc, char *argv[])
     65        psError(PS_ERR_UNKNOWN, true, "unknown image type %s", type);
     66        itype = UNKNOWN_LOOKUP_TYPE;
     67    }
     68
     69    return itype;
     70}
     71static void getParams(itOptions *options, int argnum, int *pArgc, char *argv[])
     72{
     73    if (*pArgc < 3) {
     74        fprintf(stderr, "values required for type and id\n");
     75        usage();
     76    }
     77
     78    options->imageType = parseImageType(argv[argnum]);
     79    psArgumentRemove(argnum, pArgc, argv);
     80    options->id = argv[argnum];
     81    psArgumentRemove(argnum, pArgc, argv);
     82
     83    if ((options->imageType == RAW_IMAGE) || (options->imageType == CHIP_IMAGE)) {
     84        if (*pArgc < 2) {
     85            fprintf(stderr, "value required for class_id\n");
     86            usage();
     87        }
     88        options->class_id = argv[argnum];
     89   
     90        psArgumentRemove(argnum, pArgc, argv);
     91    }
     92}
     93
     94static itOptions *parseArguments(int argc, char *argv[])
    5095{
    5196    int argnum;
    52     pspOptions *options = psAlloc(sizeof(pspOptions));
     97    itOptions *options = psAlloc(sizeof(itOptions));
     98    bool gotLookupType = false;
    5399
    54100    memset(options, 0, sizeof(*options));
    55 
    56     // options to add
    57     //      mode:   -queuejobs -execute
    58101
    59102    options->config = pmConfigRead(&argc, argv, NULL);
     
    64107    }
    65108
    66     // XXX: need to sort out the interactions of this mode option and the JOB_TYPE
    67     // listed in the request file.
    68     if ((argnum = psArgumentGet(argc, argv, "-mode"))) {
     109    if ((argnum = psArgumentGet(argc, argv, "-byid"))) {
     110        options->lookupType = BY_ID;
    69111        psArgumentRemove(argnum, &argc, argv);
    70         if (argnum == argc) {
    71             fprintf(stderr, "value required for mode\n");
     112        getParams(options, argnum, &argc, argv);
     113        gotLookupType = true;
     114    }
     115    if ((argnum = psArgumentGet(argc, argv, "-byexp"))) {
     116        if (gotLookupType) {
     117            psError(PS_ERR_UNKNOWN, false, "only one of -byid, -byexp, and -bycoord may be used\n");
    72118            usage();
    73119        }
    74         options->mode = parseMode(argv[argnum]);
     120        gotLookupType = true;
     121        options->lookupType = BY_EXP;
    75122        psArgumentRemove(argnum, &argc, argv);
    76     } else {
    77         options->mode = PSP_MODE_LIST_JOB;
    78     }
    79 
    80     if ((argnum = psArgumentGet(argc, argv, "-req_id"))) {
     123        getParams(options, argnum, &argc, argv);
     124    }
     125    if ((argnum = psArgumentGet(argc, argv, "-bycoord"))) {
     126        if (gotLookupType) {
     127            psError(PS_ERR_UNKNOWN, false, "only one of -byid, -byexp, and -bycoord may be used\n");
     128            usage();
     129        }
    81130        psArgumentRemove(argnum, &argc, argv);
    82         if (argnum == argc) {
    83             fprintf(stderr, "value required for req_id\n");
    84             usage();
    85         }
    86         options->req_id = atol(argv[argnum]);
    87         psArgumentRemove(argnum, &argc, argv);
    88     }
    89 
    90     if ((options->mode == PSP_MODE_QUEUE_JOB) && (options->req_id <= 0)) {
    91         psError(PS_ERR_UNKNOWN, true, "need request id in order to queue jobs\n");
    92         return false;
     131        gotLookupType = true;
     132        options->lookupType = BY_COORD;
     133        getParams(options, argnum, &argc, argv);
     134        psError(PS_ERR_UNKNOWN, true, "REQ_TYPE: bycoord not implemented yet");
     135        return NULL;
     136    }
     137    if (!gotLookupType) {
     138        psError(PS_ERR_BAD_PARAMETER_NULL , true, "one of -byid, -byexp, or -bycoord must be supplied\n");
     139        usage();
    93140    }
    94141
     
    102149        psArgumentRemove(argnum, &argc, argv);
    103150    }
    104     if ((argnum = psArgumentGet(argc, argv, "-out_dir"))) {
    105         psArgumentRemove(argnum, &argc, argv);
    106         if (argnum == argc) {
    107             fprintf(stderr, "value required for out_dir\n");
    108             usage();
    109         }
    110         options->outputDirectory = argv[argnum];
    111         psArgumentRemove(argnum, &argc, argv);
    112     }
    113 
    114     if (argc == 2) {
    115         options->fileName = psStringCopy(argv[1]);
    116     } else if (argc == 1) {
    117         fprintf(stderr, "input file name is required\n");
    118         usage();
    119     } else {
    120         fprintf(stderr, "unknown arguments supplied:");
    121         fprintf(stderr, " %s", argv[1]);
     151
     152    // XXX: Arguments to add for bycoord searches FILTER, DATE_BEGIN, DATE_END
     153
     154    if (argc > 1) {
     155        fprintf(stderr, "unknown arguments supplied: ");
     156
     157        fprintf(stderr, "%s", argv[1]);
    122158        for (int i=2; i<argc; i++) {
    123159            fprintf(stderr, ", %s", argv[i]);
     
    130166}
    131167
    132 static bool readRequestTable(pspOptions *options)
    133 {
    134     psFits *fitsFile = psFitsOpen(options->fileName, "r");
    135     if (fitsFile == NULL) {
    136         psError(PS_ERR_IO, false, "failed to open %s for output", options->fileName);
    137         return false;
    138     }
    139 
    140     psArray *array = psFitsReadTable(fitsFile);
    141 
    142     psFitsClose(fitsFile);
    143 
    144     if (array == NULL) {
    145         psError(PS_ERR_IO, false, "psFitsReadTable failed for %s", options->fileName);
    146         return false;
    147     }
    148 
    149     options->md = array->data[0];
    150 
    151     return true;
    152 }
    153 
    154 static bool setupDB(pspOptions *options)
     168static bool setupDB(itOptions *options)
    155169{
    156170    // XXX: need to select the database name based on the project name specified in the input
     
    166180}
    167181
    168 // TODO: move this to a shared file
    169 static pstampImageType getImageType(pspOptions *options)
    170 {
    171     psString type = psMetadataLookupStr(NULL, options->md, "IMG_TYPE");
    172     pstampImageType itype;
    173 
    174     if (type == NULL) {
    175         psError(PS_ERR_UNKNOWN, true, "NULL image type");
    176         itype = PSTAMP_UNKNOWN;
    177         return itype;
    178     }
    179 
    180     if (strcmp(type, "raw") == 0) {
    181         itype = PSTAMP_RAW;
    182     } else if (strcmp(type, "chip") == 0) {
    183         itype = PSTAMP_CHIP;
    184     } else if (strcmp(type, "warp") == 0) {
    185         itype = PSTAMP_WARP;
    186     } else if (strcmp(type, "diff") == 0) {
    187         itype = PSTAMP_DIFF;
    188     } else if (strcmp(type, "stack") == 0) {
    189         itype = PSTAMP_STACK;
    190     } else {
    191         psError(PS_ERR_UNKNOWN, true, "unknown image type %s", type);
    192         itype = PSTAMP_UNKNOWN;
    193     }
    194 
    195     return itype;
    196 }
    197182
    198183// return a string with the contents of a unsigned 64 bit value
     
    211196// the type for the values returned by the query is either a string or psU64.
    212197
    213 static psArray *runQuery(pspOptions *options, psString query, psString target,
     198static psArray *runQuery(itOptions *options, psString query, psString target,
    214199                psString key1, psString key2, bool targetIsString, psArray *output)
    215200{
     
    268253}
    269254
    270 static psArray *findURIs(pspOptions *options, psString table, psString id_type, psString id, psString class_id)
     255static psArray *findURIs(itOptions *options, psString table, psString id_type, psString id, psString class_id)
    271256{
    272257    psString query = NULL;
     
    325310
    326311
    327 static psArray *findChipURIs(pspOptions *options, psString exp_id, psString class_id)
     312static psArray *findChipURIs(itOptions *options, psString exp_id, psString class_id)
    328313{
    329314    psString chip_id = chipIDForExp(options, exp_id);
     
    340325}
    341326
    342 static psArray *findWarpURIs(pspOptions *options, psString exp_id)
     327static psArray *findWarpURIs(itOptions *options, psString exp_id)
    343328{
    344329    psString chip_id = chipIDForExp(options, exp_id);
     
    365350}
    366351
    367 static psArray *findStackURIs(pspOptions *options, psString exp_id)
     352static psArray *findStackURIs(itOptions *options, psString exp_id)
    368353{
    369354    psString chip_id = chipIDForExp(options, exp_id);
     
    406391}
    407392
    408 static psArray *findDiffURIs(pspOptions *options, psString exp_id)
     393static psArray *findDiffURIs(itOptions *options, psString exp_id)
    409394{
    410395    psString chip_id = chipIDForExp(options, exp_id);
     
    446431}
    447432
    448 static psArray * parseByID(pspOptions *options)
    449 {
    450     bool status = false;
    451     pstampImageType itype = getImageType(options);
    452     psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
    453     psString id = psMetadataLookupStr(NULL, options->md, "ID");
     433static psArray * parseByID(itOptions *options)
     434{
     435    psString id = options->id;
     436    psString class_id = options->class_id;
    454437    psArray *uris = NULL;
    455438
     
    459442    }
    460443
    461     switch (itype) {
    462     case PSTAMP_RAW:
     444    switch (options->imageType) {
     445    case RAW_IMAGE:
    463446        uris = findURIs(options, "rawImfile", "exp_id", id, class_id);
    464447        break;
    465     case PSTAMP_CHIP:
     448    case CHIP_IMAGE:
    466449        uris = findURIs(options, "chipProcessedImfile", "chip_id", id, class_id);
    467450        break;
    468     case PSTAMP_WARP:
     451    case WARP_IMAGE:
    469452        uris = findURIs(options, "warpSkyfile", "warp_id", id, NULL);
    470453        break;
    471     case PSTAMP_DIFF:
     454    case DIFF_IMAGE:
    472455        uris = findURIs(options, "diffSkyfile", "diff_id", id, NULL);
    473456        break;
    474     case PSTAMP_STACK:
     457    case STACK_IMAGE:
    475458        uris = findURIs(options, "stackSumSkyfile", "stack_id", id, NULL);
    476459        break;
    477460    default:
    478         // note: getImageType prints a message
     461        // note: parseImageType prints a message
    479462        return NULL;
    480463    }
     
    491474}
    492475
    493 psString exposureNameToID(pspOptions *options, psString exposure)
     476psString exposureNameToID(itOptions *options, psString exposure)
    494477{
    495478    psArray *results;
     
    501484}
    502485
    503 static psArray * parseByExp(pspOptions *options)
    504 {
    505     // psError(PS_ERR_UNKNOWN, true, "REQ_TYPE: byexp not implemented yet");
    506     bool status = false;
    507     pstampImageType itype = getImageType(options);
    508     psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
    509     psString exposure = psMetadataLookupStr(NULL, options->md, "EXPOSURE");
     486static psArray * parseByExp(itOptions *options)
     487{
     488    psString class_id = options->class_id;
     489    psString exposure = options->id;
    510490    psArray *uris = NULL;
    511491
     
    520500    }
    521501
    522     switch (itype) {
    523     case PSTAMP_RAW:
     502    switch (options->imageType) {
     503    case RAW_IMAGE:
    524504        if (class_id == NULL) {
    525505            // XXX: we could relax this requirement if roi is specified in sky coords and
     
    530510        uris = findURIs(options, "rawImfile", "exp_id", exp_id, class_id);
    531511        break;
    532     case PSTAMP_CHIP:
     512    case CHIP_IMAGE:
    533513        if (class_id == NULL) {
    534514            // XXX: we could relax this requirement if roi is specified in sky coords and
     
    539519        uris = findChipURIs(options, exp_id, class_id);
    540520        break;
    541     case PSTAMP_WARP:
     521    case WARP_IMAGE:
    542522        uris = findWarpURIs(options, exp_id);
    543523        break;
    544     case PSTAMP_DIFF:
     524    case DIFF_IMAGE:
    545525        uris = findDiffURIs(options, exp_id);
    546526        break;
    547     case PSTAMP_STACK:
     527    case STACK_IMAGE:
    548528        uris = findStackURIs(options, exp_id);
    549529        break;
    550530    default:
    551         // note: getImageType prints an error message
     531        // note: parseImageType prints an error message
    552532        return NULL;
    553533    }
     
    558538}
    559539
    560 static psArray * parseByCoord(pspOptions *options)
    561 {
    562     psError(PSTAMP_ERR_NOT_IMPLEMENTED, true, "REQ_TYPE: bycoord not implemented yet");
     540static psArray * parseByCoord(itOptions *options)
     541{
     542    psError(PS_ERR_UNKNOWN, true, "REQ_TYPE: bycoord not implemented yet");
    563543    return NULL;
    564544}
    565545
    566 static psString parseROI(pspOptions *options)
    567 {
     546static psString parseROI(itOptions *options)
     547{
     548    psString roiString = NULL;
     549#ifdef notyet
    568550    bool status = false;;
    569     psString roiString = NULL;
    570 
    571551    psU32 coord_mask = psMetadataLookupU32(&status, options->md, "COORD_MASK");
    572552    if (!status) {
     
    609589    }
    610590
     591#endif
    611592    return roiString;
    612593}
    613594
    614595static bool
    615 queueOneJob (pspOptions *options, psString job_type, psString uri, psString outputBase, psString commandArgs)
    616 {
    617     psString cmd = NULL;
    618 
    619     psStringAppend(&cmd, "pstamptool -addjob -req_id %" PRId64 " -job_type %s -uri %s ",
    620         options->req_id, job_type, uri);
    621 
    622     if (outputBase != NULL) {
    623         psStringAppend(&cmd, "-outputBase ");
    624 
    625         if (options->outputDirectory) {
    626             psStringAppend(&cmd, "%s/", options->outputDirectory);
    627         }
    628         psStringAppend(&cmd, "%s", outputBase);
    629     }
    630     if (commandArgs) {
    631         psStringAppend(&cmd, " -args '%s'", commandArgs);
    632     }
    633     // XXX We may want to have the data store name be different than the default DB
    634     psBool status;
    635     psString dbName = psMetadataLookupStr(&status, options->config->complete, "DBNAME");
    636     fprintf(stderr, "\n\n   dbName is %s\n", dbName);
    637     if (dbName) {
    638         psStringAppend(&cmd, " -dbname %s", dbName);
    639     }
    640 
    641     psStringAppend(&cmd, " > /dev/null");
    642 
    643     if (options->verbose) {
    644         fprintf(stderr, "excuting system(%s)\n", cmd);
    645     }
    646 
    647     int rstatus = system(cmd);
    648 
    649     if (rstatus) {
    650         fprintf(stderr, "%s failed with status: %d\n", cmd, rstatus);
    651     }
    652     psFree(cmd);
    653 
    654     // TODO: should we be returning the exit status so that it can be reported?
    655     return !rstatus;
    656 }
    657 
    658 static bool
    659 queueJobs (pspOptions *options, psString job_type, psArray *uris, psString stamp_name, psString commandArgs)
    660 {
    661     int numURIs = psArrayLength(uris);
    662     bool status = false;
    663 
    664     if (numURIs == 1) {
    665         // use the user tag as the outputBase
    666         status = queueOneJob(options, job_type, uris->data[0], stamp_name, commandArgs);
    667     } else {
    668         for (int i = 0; i< numURIs; i++) {
    669             psString outputBase = NULL;
    670 
    671             // append an integer to the stamp_name to get a uniqueu outputBase
    672             psStringAppend(&outputBase, "%s_%d", stamp_name, i);
    673 
    674             status = queueOneJob(options, job_type, uris->data[i], outputBase, commandArgs);
    675             psFree(outputBase);
    676 
    677             if (!status) {
    678                 break;
    679             }
    680         }
    681     }
    682 
    683     return status;
    684 }
    685 
    686 static bool
    687 turnOnResultsFile(pspOptions *options)
    688 {
    689     // turn off the creation of a results file for this request
    690     char * query = "UPDATE pstampRequest SET resultsFile = 1 WHERE req_id = %" PRId64;
    691     return p_psDBRunQuery(options->config->database, query, options->req_id);
    692 }
    693 
    694 static bool
    695 queueGetImageJob(pspOptions *options, psArray *uris, psString req_type)
    696 {
    697     FILE        *listFile;
    698     psString    fileName = NULL;
    699     psString    img_type = psMetadataLookupStr(NULL, options->md, "IMG_TYPE");
    700 
    701 #ifdef notdef
    702     if (! turnOffResultsFile(options)) {
    703         fprintf(stderr, "failed to update resultsFile for request %" PRId64 "\n", options->req_id);
    704         return false;
    705     }
    706 #endif
    707 
    708     if (options->outputDirectory == NULL) {
    709         fprintf(stderr, "outputDirectory is required\n");
    710         return false;
    711     }
    712     psStringAppend(&fileName, "%s/filelist", options->outputDirectory);
    713 
    714     listFile = fopen(fileName, "w");
    715     if (listFile == NULL) {
    716         psError(PS_ERR_UNKNOWN, true, "failed to open get_image file list: %s\n", fileName);
    717         return false;
    718     }
    719 
    720     for (int i=0; i<psArrayLength(uris); i++) {
    721         fprintf(listFile, "%s|%s\n", (psString) uris->data[i], img_type);
    722     }
    723     fclose(listFile);
    724 
    725     psString cmd = NULL;
    726     psStringAppend(&cmd, "pstamptool -addjob -req_id %" PRId64 " -job_type get_image -uri %s -outputBase %s",
    727         options->req_id, fileName, options->outputDirectory);
    728 
    729     int rstatus = system(cmd);
    730     if (rstatus) {
    731         fprintf(stderr, "%s failed with status: %d\n", cmd, rstatus);
    732     }
    733 
    734     return rstatus == 0;
    735 }
    736 
    737 
    738 static bool
    739 parseRequestTable(pspOptions *options)
    740 {
    741     bool status = false;
    742 
    743     psString job_type = psMetadataLookupStr(&status, options->md, "JOB_TYPE");
    744     if (job_type == NULL) {
    745         psError(PS_ERR_UNKNOWN, true, "bad request file: JOB_TYPE not specified");
    746         return false;
    747     }
    748 
    749     bool isStampJob = (strcmp(job_type, "stamp") == 0);
    750 
     596go(itOptions *options)
     597{
    751598    // how are we to select the images ?
    752     psString req_type = psMetadataLookupStr(&status, options->md, "REQ_TYPE");
    753     if ( !req_type) {
     599    if (options->lookupType == UNKNOWN_LOOKUP_TYPE) {
    754600        psError(PS_ERR_UNKNOWN, true, "request file has no REQ_TYPE");
    755601        return false;
     
    757603
    758604    psString roiString = parseROI(options);
    759     if (isStampJob && !roiString) {
    760         psError(PS_ERR_UNKNOWN, false, "need valid ROI for stamp request");
    761         return false;
    762     }
    763605
    764606    psArray *uris = NULL;
    765607
    766     if (!strcmp(req_type, "byid")) {
     608    switch (options->lookupType) {
     609    case BY_ID:
    767610        // directly by exp_id, chip_id, warp_id etc
    768 
    769611        uris = parseByID(options);
    770     } else if (!strcmp(req_type, "byexp")) {
     612        break;
     613    case BY_EXP:
    771614        // images that resulted from a given exposure
    772 
    773615        uris = parseByExp(options);
    774     } else if (!strcmp(req_type, "bycoord")) {
     616        break;
     617    case BY_COORD:
    775618        // images from a particular region of the sky
    776 
    777619        if (!roiString) {
    778             fprintf(stderr, "Region of interest required with req_type: bycoord\n");
     620            fprintf(stderr, "Region of interest required with lookupType: bycoord\n");
    779621            return false;
    780622        }
    781623        uris = parseByCoord(options);
    782     } else {
    783 
    784         psError(PS_ERR_UNKNOWN, true, "unknown REQ_TYPE: %s", req_type);
     624        break;
     625    default:
     626        psError(PS_ERR_PROGRAMMING, true, "unknown Lookup type: %d\n", options->lookupType);
    785627        return false;
    786628    }
     
    790632        // or are there simply no images matching the request
    791633        fprintf(stderr, "No matching images found.\n");
    792         return false;
     634        // don't return an error
     635        return true;
    793636    }
    794637
    795638    int numURIs = psArrayLength(uris);
    796     if (options->mode == PSP_MODE_LIST_URI) {
    797         // Just list the images that would have jobs queued for them
    798         for (int i=0; i<numURIs; i++) {
    799             fprintf(stdout, "%s\n", (psString) uris->data[i]);
    800         }
    801     } else {
    802         psString commandArgs = roiString;
    803         psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID");
    804         // We don't check here whether class_id is required. We leave that up to
    805         // ppstamp
    806         if (class_id && strcmp(class_id, "null")) {
    807             // TODO: the ppstamp argument needs to change to class_id
    808             // perhaps allow chip as a synonym
    809             psStringAppend(&commandArgs, " -chip %s", class_id);
    810         }
    811         psString stamp_name = psMetadataLookupStr(&status, options->md, "STAMP_NAME");
    812 
    813         if (options->mode == PSP_MODE_LIST_JOB) {
    814             if (numURIs == 1) {
    815                 printf("%s %s %s %s\n", job_type, (psString) uris->data[0],
    816                     stamp_name ? stamp_name : "", commandArgs ? commandArgs : "") ;
    817             } else {
    818                 // add an integer to the stamp_name
    819                 for (int i = 0; i < numURIs; i++) {
    820                     printf("%s %s %s_%d %s\n", job_type, (psString) uris->data[i], stamp_name, i,
    821                         commandArgs ? commandArgs :"");
    822                 }
    823             }
    824         } else if (options->mode == PSP_MODE_QUEUE_JOB) {
    825 
    826             if (!strcmp(job_type, "stamp")) {
    827                 // Postage stamp job
    828                 if (stamp_name == NULL) {
    829                     psError(PS_ERR_UNKNOWN, true, "no STAMP_NAME in request file");
    830                     return false;
    831                 }
    832 
    833                 if (!queueJobs(options, job_type, uris, stamp_name, commandArgs)) {
    834                     return false;
    835                 }
    836 
    837                 // Note: This is a DB operation
    838                 if (!turnOnResultsFile(options)) {
    839                     psError(PS_ERR_UNKNOWN, true, "failed to update resultsFile");
    840 
    841                     // TODO: should we unqueue the jobs, set state of request to false??
    842                     // Maybe get rid of the column and just use job_type to trigger creation of
    843                     // results file. so what if the gui doesn't need it?
    844                     return false;
    845                 }
    846             } else {
    847                 return queueGetImageJob(options, uris, req_type);
    848             }
    849 
    850         } else {
    851             // this error is actually caught by parseMode
    852             fprintf(stderr, "unknown command mode found: %d\n", options->mode);
    853             exit(1);
    854         }
     639    // Just list the images that would have jobs queued for them
     640    for (int i=0; i<numURIs; i++) {
     641        fprintf(stdout, "%s\n", (psString) uris->data[i]);
    855642    }
    856643
     
    860647int main(int argc, char *argv[])
    861648{
    862     pspOptions *options = parseArguments(argc, argv);
    863 
    864     // XXX: create a set of status codes to return so the
    865     // scripts can distinguish between different errors.
    866     // For example:
    867     //      If we can't connect to the DB it's a configuration problem.
    868     //      If a particular image doesn't contain coordinates specified that's a user "error"
    869     //      if there are no images of a particular ROI outside of a date range, that tells us
    870     //      something
    871 
    872     if (!options) {
    873         psErrorStackPrint(stderr, "unable to parse arguments");
    874         return 1;
    875     }
    876 
    877     if (!readRequestTable(options)) {
    878         psErrorStackPrint(stderr, "unable to read request table");
    879         return 1;
    880     }
     649    itOptions *options = parseArguments(argc, argv);
    881650
    882651    if (!setupDB(options)) {
     
    885654    }
    886655
    887     if (options->verbose) {
    888         psMetadataPrint(stderr, options->md, 0);
    889     }
    890 
    891     if (!parseRequestTable(options)) {
    892         psErrorStackPrint(stderr, "unable to parse request table");
     656    if (!go(options)) {
     657        psErrorStackPrint(stderr, "error processing request");
    893658        return 1;
    894659    }
Note: See TracChangeset for help on using the changeset viewer.